diff --git a/backend/postgres-init/init.sql b/backend/postgres-init/init.sql index 0c71889..7963676 100644 --- a/backend/postgres-init/init.sql +++ b/backend/postgres-init/init.sql @@ -41,6 +41,16 @@ CREATE TABLE IF NOT EXISTS public.weather_daily ( -- 구별 층별 구름. 출처: Open-Meteo. 노을·일출 점수용 (구 중심에서 해 지는 쪽·뜨는 쪽 20·100km 지점). -- 점수에 쓰는 시각(그날 일몰·일출에 가장 가까운 정시) 값만 넣는다. +-- 예전 구조(좌표 키)면 지우고 새로 만든다. 외부 API 에서 받은 임시 값이라 지워도 다시 받는다. 옛 방식 노을 점수도 같이 비워 다시 계산. +DO $$ BEGIN + IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'cloud_hourly') + AND NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'cloud_hourly' AND column_name = 'region_code') THEN + DROP TABLE public.cloud_hourly; + IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'sky_score') THEN + DELETE FROM public.sky_score; + END IF; + END IF; +END $$; CREATE TABLE IF NOT EXISTS public.cloud_hourly ( region_code VARCHAR(10) NOT NULL, -- region.code kind SMALLINT NOT NULL, -- SkyType: 1=일몰 방향 2=일출 방향 @@ -146,6 +156,9 @@ CREATE TABLE IF NOT EXISTS public.index_score ( computed_at TIMESTAMPTZ NOT NULL DEFAULT now(), PRIMARY KEY (region_code, score_date, index_id) ); +ALTER TABLE public.index_score ADD COLUMN IF NOT EXISTS uv_score SMALLINT NOT NULL DEFAULT 0; +ALTER TABLE public.index_score ADD COLUMN IF NOT EXISTS sun_score SMALLINT NOT NULL DEFAULT 0; +ALTER TABLE public.index_score ADD COLUMN IF NOT EXISTS view_score SMALLINT NOT NULL DEFAULT 0; -- 피드 카드. 매일 03:00 스케줄러가 그날 카드를 전부 만들고, 볼 때 시간대에 따라 켜고 끄고 순서를 정해 그 구 데이터로 채운다. CREATE TABLE IF NOT EXISTS public.post ( @@ -275,6 +288,9 @@ CREATE TABLE IF NOT EXISTS public.index_definition ( sentences JSONB NOT NULL DEFAULT '{}', -- 문장 틀 {summary, headline, rabbit, bear, notes} sort_order SMALLINT NOT NULL DEFAULT 0 ); +ALTER TABLE public.index_definition ADD COLUMN IF NOT EXISTS weight_uv SMALLINT NOT NULL DEFAULT 0; +ALTER TABLE public.index_definition ADD COLUMN IF NOT EXISTS weight_sun SMALLINT NOT NULL DEFAULT 0; +ALTER TABLE public.index_definition ADD COLUMN IF NOT EXISTS weight_view SMALLINT NOT NULL DEFAULT 0; -- 노을 명소. CREATE TABLE IF NOT EXISTS public.sunset_spot (