Skip to content

Commit 5cfa8a1

Browse files
committed
feat/ #35 코드 리뷰 반영
1 parent c9a4d2d commit 5cfa8a1

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,17 @@ dependencies {
6161

6262
tasks.named('test') {
6363
useJUnitPlatform()
64+
65+
def envFile = rootProject.file('.env')
66+
if (envFile.exists()) {
67+
envFile.readLines().each { line ->
68+
line = line.trim()
69+
if (!line.startsWith('#') && line.contains('=')) {
70+
def idx = line.indexOf('=')
71+
def key = line.substring(0, idx).trim()
72+
def value = line.substring(idx + 1).trim()
73+
environment key, value
74+
}
75+
}
76+
}
6477
}

src/main/resources/db/migration.sql

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
-- =====================================================================
55

66
-- 1. version 컬럼 추가 (낙관적 락)
7+
-- ddl-auto: update 환경에서는 앱 재시작 시 자동 추가됨
78
ALTER TABLE `clothes`
89
ADD COLUMN `version` BIGINT NOT NULL DEFAULT 0;
910

11+
-- =====================================================================
12+
-- 아래 구문은 기존 데이터가 있을 경우에만 실행하세요.
13+
-- 로컬 개발 환경은 DB를 초기화 후 앱을 재시작하면 됩니다.
14+
-- =====================================================================
15+
1016
-- 2. 기존 clothes.color → clothing_colors 백필
1117
-- (기존 테이블에 color VARCHAR 컬럼이 있었던 경우)
1218
-- INSERT INTO `clothing_colors` (clothes_id, color_code, color_role, sort_order, created_at, updated_at)
13-
-- SELECT id, color, 'PRIMARY', 0, NOW(), NOW()
19+
-- SELECT clothes_id, color, 'PRIMARY', 0, NOW(), NOW()
1420
-- FROM `clothes`
1521
-- WHERE color IS NOT NULL;
1622

@@ -21,7 +27,7 @@ ALTER TABLE `clothes`
2127
-- registration_source, user_image_url, created_at, updated_at)
2228
-- SELECT
2329
-- wardrobe_id,
24-
-- id,
30+
-- clothes_id,
2531
-- source_type, -- 'OWNED' or 'WISHLIST'
2632
-- 'FREE', -- size 기본값 (실제 값으로 교체)
2733
-- NULL, -- season
@@ -33,8 +39,23 @@ ALTER TABLE `clothes`
3339
-- FROM `clothes`
3440
-- WHERE wardrobe_id IS NOT NULL;
3541

36-
-- 4. 이전 완료 후 기존 컬럼 제거
37-
-- (데이터 검증 후 실행)
42+
-- 4. clothing_styles에 style_role, sort_order 컬럼 추가된 경우 백필
43+
-- (기존 clothing_styles row에 해당 컬럼이 NULL인 경우)
44+
-- ALTER TABLE `clothing_styles`
45+
-- ADD COLUMN IF NOT EXISTS `style_role` VARCHAR(20) NOT NULL DEFAULT 'PRIMARY',
46+
-- ADD COLUMN IF NOT EXISTS `sort_order` TINYINT NOT NULL DEFAULT 0;
47+
--
48+
-- -- 첫 번째 스타일은 PRIMARY, 나머지는 SECONDARY로 설정
49+
-- UPDATE `clothing_styles` cs
50+
-- JOIN (
51+
-- SELECT clothes_id, style_id,
52+
-- ROW_NUMBER() OVER (PARTITION BY clothes_id ORDER BY clothing_style_id) AS rn
53+
-- FROM `clothing_styles`
54+
-- ) ranked ON cs.clothes_id = ranked.clothes_id AND cs.style_id = ranked.style_id
55+
-- SET cs.style_role = IF(ranked.rn = 1, 'PRIMARY', 'SECONDARY'),
56+
-- cs.sort_order = ranked.rn - 1;
57+
58+
-- 5. 이전 완료 후 기존 컬럼 제거 (데이터 검증 후 실행)
3859
-- ALTER TABLE `clothes` DROP COLUMN `color`;
3960
-- ALTER TABLE `clothes` DROP COLUMN `wardrobe_id`;
4061
-- ALTER TABLE `clothes` DROP COLUMN `is_favorite`;

0 commit comments

Comments
 (0)