Files
accounted/supabase/migrations/20260616120000_transactions_date_sane_range.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

33 lines
1.3 KiB
SQL

-- Backstop against malformed transaction dates.
--
-- The manual "add transaction" form historically inserted straight into
-- `transactions` via the browser Supabase client (no server route, no
-- server-side validation). A native <input type="date"> whose year subfield is
-- over-typed can emit a 6-digit year (e.g. '202403-02-05' = year 202403);
-- Postgres' `date` type accepts it, the row saves, and every date-fns formatter
-- then throws RangeError on render — taking down the whole dashboard route via
-- the error boundary. (Real incident, 2026-06: company 4e4e41e7 locked out of
-- the transactions page.)
--
-- This CHECK is the database-level guard: an out-of-range date is rejected at
-- INSERT/UPDATE instead of silently corrupting a row. The window is wide on
-- purpose — it only rejects garbage, never a legitimate accounting date.
-- CHECK expressions must be immutable, so we cannot bound against CURRENT_DATE.
--
-- Idempotent: safe to re-run / replay on preview branches.
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_constraint
WHERE conname = 'transactions_date_sane_range'
AND conrelid = 'public.transactions'::regclass
) THEN
ALTER TABLE public.transactions
ADD CONSTRAINT transactions_date_sane_range
CHECK (date >= DATE '1900-01-01' AND date <= DATE '2100-12-31');
END IF;
END $$;
NOTIFY pgrst, 'reload schema';