Files
accounted/supabase/migrations/20260518090000_document_attachments_extraction_columns.sql
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

30 lines
1.3 KiB
SQL

-- Migration: document_attachments AI-extraction columns
--
-- Adds columns the document-extraction extension (paid AI tier) writes to
-- when it runs Sonnet on a freshly uploaded receipt or invoice. The agent
-- composer + chat intents read these to surface "what we already know"
-- without re-asking the user.
--
-- All three columns are nullable so:
-- * The free tier (no extraction extension) leaves them as-is — uploads
-- still work, agent UI degrades gracefully.
-- * Older documents predating this migration stay readable; a backfill
-- job can populate retroactively later.
-- * Failed extractions can be distinguished from never-attempted by
-- looking at extracted_at (set on attempt) vs extracted_data (null on
-- failure).
ALTER TABLE public.document_attachments
ADD COLUMN extracted_data jsonb,
ADD COLUMN extracted_at timestamptz,
ADD COLUMN extraction_model text;
-- Partial index for the "needs extraction" backfill / retry job: rows
-- that have never been attempted. Sparse — most production rows will
-- have extracted_at set after the handler runs.
CREATE INDEX idx_document_attachments_pending_extraction
ON public.document_attachments (company_id, created_at)
WHERE extracted_at IS NULL;
NOTIFY pgrst, 'reload schema';