-- Link pipeline creatives to RRSS calendar pieces (documents content.pieces[].id). -- Idempotent. alter table public.creative_pipeline add column if not exists calendar_piece_id text; create index if not exists creative_pipeline_calendar_piece_idx on public.creative_pipeline (tenant_id, calendar_piece_id) where calendar_piece_id is not null; comment on column public.creative_pipeline.calendar_piece_id is 'Stable id of the RRSS calendar piece (documents type=calendar → pieces[].id). Agency links pipeline ↔ editorial plan.';