Skip to content

Commit d714f2b

Browse files
committed
fix: 쿼리 조건, 중복 방지 추가
1 parent 6c44028 commit d714f2b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/resources/db/migration/V9__migrate_cheer_story_images.sql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ SELECT c.id,
55
c.created_at
66
FROM cheer c
77
WHERE c.image_key IS NOT NULL
8-
AND c.image_key != '';
8+
AND c.image_key != ''
9+
AND NOT EXISTS (SELECT 1
10+
FROM cheer_image ci
11+
WHERE ci.cheer_id = c.id
12+
AND ci.order_index = 1);
913

1014
INSERT INTO story_image (story_id, image_key, order_index, created_at)
1115
SELECT s.id,
@@ -14,7 +18,11 @@ SELECT s.id,
1418
s.created_at
1519
FROM story s
1620
WHERE s.image_key IS NOT NULL
17-
AND s.image_key != '';
21+
AND s.image_key != ''
22+
AND NOT EXISTS (SELECT 1
23+
FROM story_image si
24+
WHERE si.story_id = s.id
25+
AND si.order_index = 1);
1826

1927
ALTER TABLE cheer RENAME COLUMN image_key TO _deprecated_image_key;
2028
ALTER TABLE story RENAME COLUMN image_key TO _deprecated_image_key;

0 commit comments

Comments
 (0)