Files
accounted/supabase/migrations/20260517160000_narrative_agm_date_and_composite_unique.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

27 lines
1.2 KiB
SQL

-- Two changes to arsredovisning_narratives:
--
-- 1. Add agm_date column. The fastställelseintyg page (added in PR #511)
-- has a blank for the stämma-date the user has to fill in by hand,
-- which defeats the purpose of a generated document. With this column
-- the user records the AGM date once and the PDF picks it up.
--
-- 2. Change the UNIQUE constraint from (fiscal_period_id) to
-- (company_id, fiscal_period_id). The previous constraint relied on
-- UUIDs not colliding across tenants for isolation — true in practice,
-- but the constraint itself should match the tenant boundary so a logic
-- error in onConflict resolution can never overwrite another company's
-- narrative. RLS would also reject the cross-tenant write, but
-- constraint-level enforcement is stronger defense-in-depth.
ALTER TABLE public.arsredovisning_narratives
ADD COLUMN IF NOT EXISTS agm_date DATE;
ALTER TABLE public.arsredovisning_narratives
DROP CONSTRAINT IF EXISTS arsredovisning_narratives_unique_period;
ALTER TABLE public.arsredovisning_narratives
ADD CONSTRAINT arsredovisning_narratives_unique_period
UNIQUE (company_id, fiscal_period_id);
NOTIFY pgrst, 'reload schema';