-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathschedules_migration_complete.sql
More file actions
57 lines (44 loc) · 1.67 KB
/
schedules_migration_complete.sql
File metadata and controls
57 lines (44 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-- ========================================
-- Schedules 테이블 완전 마이그레이션 SQL
-- weather_info, mood_data, accommodations, restaurants 포함 전체 버전
-- 한 번에 실행 가능 ✅
-- ========================================
-- 1. weather_info 컬럼 추가 (없으면)
alter table schedules
add column if not exists weather_info jsonb;
-- 2. mood_data 컬럼 추가 (없으면)
alter table schedules
add column if not exists mood_data jsonb;
-- 3. accommodations 컬럼 추가
alter table schedules
add column if not exists accommodations jsonb default '[]'::jsonb;
-- 4. restaurants 컬럼 추가
alter table schedules
add column if not exists restaurants jsonb default '[]'::jsonb;
-- 5. people 컬럼 타입 변경 (데이터 보존)
-- 만약 people이 없다면 추가
alter table schedules
add column if not exists people smallint default 1 not null;
-- 이미 있다면 타입만 변경
alter table schedules
alter column people type smallint using people::smallint;
-- 6. jsonb 컬럼들의 NOT NULL 제약조건 제거
alter table schedules
alter column weather_info drop not null;
alter table schedules
alter column mood_data drop not null;
alter table schedules
alter column accommodations drop not null;
alter table schedules
alter column restaurants drop not null;
-- 7. 기존 행들의 null 값을 빈 배열로 업데이트
update schedules
set accommodations = '[]'::jsonb
where accommodations is null;
update schedules
set restaurants = '[]'::jsonb
where restaurants is null;
-- ========================================
-- ✅ 완료!
-- weather_info, mood_data 포함 모든 컬럼 준비됨
-- ========================================