o2o-site-AEO/postgres-init/migrations/0015_owner_social_accounts.sql
hbyang 58d6249102 Merge remote-tracking branch 'origin/main' into feature/social-post
# Conflicts:
#	docs/DECISIONS.md
#	docs/DEVLOG.md
#	solution/backend/requirements.txt
#	solution/backend/scheduler/__init__.py
#	solution/backend/worker/handlers.py
#	solution/site/src/pages/HomePage.tsx
#	solution/site/src/sections/index.ts
2026-09-16 08:46:48 +09:00

25 lines
1.3 KiB
SQL

-- 0015 · SNS 계정 연결
--
-- ★ 번호가 0012·0013 이었는데 main 에 같은 번호가 이미 있어서(0012_place_faqs_template_source,
-- 0013_job_progress) 병합하며 뒤로 밀었다. migrate.py 는 파일명 정렬로 돌고 적용 이력도
-- 파일명(stem)으로 남기므로, 이미 옛 이름으로 적용된 DB 는 이 파일을 한 번 더 돌린다 —
-- 안에 있는 문장이 전부 IF NOT EXISTS 라 두 번 돌아도 결과가 같다(그래서 밀 수 있었다).
CREATE TABLE IF NOT EXISTS public.owner_social_accounts (
account_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
user_id uuid NOT NULL,
provider smallint NOT NULL CHECK (provider IN (1,2)),
provider_user_id varchar(200) NOT NULL,
handle varchar(200) NOT NULL,
profile_url text NOT NULL,
access_token text,
refresh_token text,
access_expires_at timestamptz,
scopes jsonb NOT NULL DEFAULT '[]',
status varchar(20) NOT NULL DEFAULT 'linked',
last_error text,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted boolean NOT NULL DEFAULT false
);
CREATE UNIQUE INDEX IF NOT EXISTS uq_social_account ON public.owner_social_accounts(user_id, provider) WHERE deleted=false AND status IN ('linked','needs_reauth');