Files
accounted/supabase/migrations/20260517150000_sie_imports_active_partial_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

23 lines
1.0 KiB
SQL

-- Capture the partial unique index on sie_imports that already exists in
-- production but was never expressed as a repo migration (schema drift).
--
-- The plain UNIQUE (company_id, file_hash) constraint added in
-- 20260330130000_multi_tenant_company_refactor.sql blocks a fiscal-year
-- re-sync from Fortnox: the prior 'completed' row keeps the slot even
-- though we want a new import to take its place (with the old one marked
-- 'replaced'). The partial index relaxes uniqueness for 'replaced' and
-- 'failed' rows so a replace-and-reimport works.
--
-- Both statements are idempotent. Against production this migration is a
-- no-op; on dev/staging databases that still carry the plain constraint
-- it brings them in line.
CREATE UNIQUE INDEX IF NOT EXISTS sie_imports_company_id_file_hash_active_idx
ON public.sie_imports (company_id, file_hash)
WHERE status <> ALL (ARRAY['replaced'::text, 'failed'::text]);
ALTER TABLE public.sie_imports
DROP CONSTRAINT IF EXISTS sie_imports_company_id_file_hash_key;
NOTIFY pgrst, 'reload schema';