Files
accounted/supabase/migrations/20260418150000_company_settings_default_voucher_series.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

42 lines
1.8 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Add default_voucher_series to company_settings.
--
-- The frontend (/settings/bookkeeping) and TypeScript types have referenced
-- this column for a while, but no migration ever added it, so saving the form
-- failed with: "Could not find the 'default_voucher_series' column of
-- 'company_settings' in the schema cache".
--
-- The column stores the per-company default voucher series (A–Z) that is
-- pre-selected when booking manual journal entries. The actual sequence
-- counters live in public.voucher_sequences, keyed on (user_id,
-- fiscal_period_id, voucher_series) — this setting only controls the UI
-- default.
ALTER TABLE public.company_settings
ADD COLUMN IF NOT EXISTS default_voucher_series text NOT NULL DEFAULT 'A';
-- ADD COLUMN IF NOT EXISTS silently skips the whole column definition
-- (including NOT NULL) when the column already exists. Re-apply the
-- constraint explicitly so environments that received the column
-- out-of-band still end up with the same schema.
ALTER TABLE public.company_settings
ALTER COLUMN default_voucher_series SET DEFAULT 'A';
UPDATE public.company_settings
SET default_voucher_series = 'A'
WHERE default_voucher_series IS NULL;
ALTER TABLE public.company_settings
ALTER COLUMN default_voucher_series SET NOT NULL;
-- Match the Zod validation in lib/api/schemas.ts so DB and app stay in sync.
ALTER TABLE public.company_settings
DROP CONSTRAINT IF EXISTS company_settings_default_voucher_series_check;
ALTER TABLE public.company_settings
ADD CONSTRAINT company_settings_default_voucher_series_check
CHECK (default_voucher_series ~ '^[A-Z]$');
-- Reload PostgREST schema cache so the column becomes visible to the API
-- immediately, without waiting for the next automatic reload.
NOTIFY pgrst, 'reload schema';