-- 서포터즈 자동 빌드 (v2 §7-5·§7-6, §12-3) -- supporter_builds : 병원 URL 하나당 빌드 실행 기록. 워커가 단계마다 갱신하고 랜딩이 폴링한다. -- supporter_inputs : 병원(고객)이 입력하는 값 (v2 §6 9항목 + 글별 검토·승인). 최신 행이 유효값. -- RLS: 익명은 inputs insert/select 와 builds select 만. 쓰기(빌드 상태)는 service_role(워커) 전용. create table if not exists public.supporter_builds ( id uuid primary key default gen_random_uuid(), lead_id uuid references public.discovery_leads(id) on delete set null, clinic_id text not null, -- 예: viewclinic. discovery 결과 id 와 같은 값 url text not null, -- 병원 홈페이지 status text not null default 'queued', -- queued | running | gate_failed | failed | preview | approved | published phase text, -- 현재/마지막 단계 이름 (evidence, data, posts, build, gate, deploy, audit) phases jsonb not null default '[]', -- [{phase, status, startedAt, finishedAt, summary, log}] posts jsonb not null default '[]', -- [{id, title, category, reviewer, reviewStatus, approvedAt}] preview_url text, report jsonb, -- 생성기 report.summary + 게이트 결과 error text, created_at timestamptz not null default now(), updated_at timestamptz not null default now() ); create index if not exists supporter_builds_clinic_idx on public.supporter_builds (clinic_id, created_at desc); create table if not exists public.supporter_inputs ( id uuid primary key default gen_random_uuid(), clinic_id text not null, key text not null, -- author | editor | sponsorship | quote_items | recovery | revision_policy | discrepancy | specialty_doctors | domain | post_review | post_approval post_id text, -- post_review / post_approval 일 때 글 slug value jsonb not null, input_by text, -- 입력자 이름·직함 (병원 담당자) created_at timestamptz not null default now() ); create index if not exists supporter_inputs_clinic_idx on public.supporter_inputs (clinic_id, key, post_id, created_at desc); alter table public.supporter_builds enable row level security; alter table public.supporter_inputs enable row level security; create policy "anon can read builds" on public.supporter_builds for select to anon using (true); create policy "anon can read inputs" on public.supporter_inputs for select to anon using (true); create policy "anon can insert inputs" on public.supporter_inputs for insert to anon with check (true); comment on table public.supporter_builds is '서포터즈 사이트 자동 빌드 실행 기록. 워커(service_role)가 갱신, 랜딩 /discovery/:id 가 폴링.'; comment on table public.supporter_inputs is '병원 확인 항목 입력(v2 §6). 같은 clinic_id·key·post_id 의 최신 행이 유효값. apply_inputs.mjs 가 데이터 파일에 반영.';