-- 0008_entity_summaries.sql — bilingual prose summary per entity.
--
-- The /sightings, /witnesses, /objects, /locations, /operations pages
-- need real prose to feel like a magazine. Today they show just a name +
-- mention count. After this migration, each entity carries an ~80-word
-- bilingual narrative summary written from the chunks where it appears.
--
-- The narrator (case-writer voice, house style) writes one summary per
-- entity. Generation is offline (scripts/maintain/61_enrich_entity_summaries.ts)
-- and idempotent — re-running the script skips rows already enriched.
--
-- Apply as supabase_admin (entities table owner).

BEGIN;

ALTER TABLE public.entities
  ADD COLUMN IF NOT EXISTS summary_en           TEXT,
  ADD COLUMN IF NOT EXISTS summary_pt_br        TEXT,
  ADD COLUMN IF NOT EXISTS summary_generated_at TIMESTAMPTZ,
  ADD COLUMN IF NOT EXISTS summary_model        TEXT,
  ADD COLUMN IF NOT EXISTS summary_status       TEXT
    CHECK (summary_status IN ('pending', 'ai_generated', 'curated', 'refused'));

CREATE INDEX IF NOT EXISTS entities_summary_status_idx
  ON public.entities (summary_status) WHERE summary_status IS NOT NULL;

COMMIT;
