From 0b863158f3bd12844110cdd910490f7be978abfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A0=95=EB=B9=88?= Date: Wed, 15 Apr 2026 01:06:48 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20exp=20=EB=8F=99=EA=B8=B0=ED=99=94=20fly?= =?UTF-8?q?way=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../V38__sync_user_exp_with_history.sql | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/resources/db/migration/V38__sync_user_exp_with_history.sql diff --git a/src/main/resources/db/migration/V38__sync_user_exp_with_history.sql b/src/main/resources/db/migration/V38__sync_user_exp_with_history.sql new file mode 100644 index 000000000..e09fd8b6f --- /dev/null +++ b/src/main/resources/db/migration/V38__sync_user_exp_with_history.sql @@ -0,0 +1,21 @@ +-- 베타 시즌 종료 후 일괄 exp 회수로 인해 users.total_exp가 +-- user_exp_history 누적 합계와 불일치하는 상태를 동기화한다. +-- earn_exp 합계가 음수가 되는 경우(회수 이후 추가 획득 없는 유저)는 0으로 처리한다. + +UPDATE users u +SET total_exp = GREATEST(0, COALESCE( + (SELECT SUM(ueh.earn_exp) + FROM user_exp_history ueh + WHERE ueh.fk_user_id = u.id), + 0 +)); + +-- 보정된 total_exp 기준으로 current_exp_tier 재계산 +UPDATE users +SET current_exp_tier = CASE + WHEN total_exp >= 100000 THEN 'DIAMOND' + WHEN total_exp >= 30000 THEN 'GOLD' + WHEN total_exp >= 10000 THEN 'SILVER' + WHEN total_exp >= 1000 THEN 'BRONZE' + ELSE 'UNRANKED' +END; \ No newline at end of file