Files
accounted/supabase/migrations/20260719102000_deadline_horizon_cleanup.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

-- One-time cleanup for the rolling generation horizon.
--
-- Deadline rows used to be generated through the end of next calendar year
-- (~17 months of future rows in mid-year). The generator now caps recurring
-- skattekonto obligations at ~6 months ahead and annual obligations at 12
-- months; the daily backfill cron creates rows as they enter the window.
-- Existing pending rows beyond the horizon would otherwise linger until the
-- company's next full regeneration, so delete them here. Completed and
-- dismissed rows are untouched (filing progress and opt-outs survive), and
-- every deleted row is recreated automatically once its due date comes back
-- into view.
DELETE FROM public.deadlines
WHERE source = 'system'
AND deadline_type = 'tax'
AND is_completed = FALSE
AND dismissed_at IS NULL
AND (
(
tax_deadline_type IN (
'moms_monthly', 'moms_quarterly', 'f_skatt',
'arbetsgivardeklaration', 'skatteinbetalning', 'periodisk_sammanstallning'
)
AND due_date > (CURRENT_DATE + INTERVAL '183 days')
)
OR (
tax_deadline_type NOT IN (
'moms_monthly', 'moms_quarterly', 'f_skatt',
'arbetsgivardeklaration', 'skatteinbetalning', 'periodisk_sammanstallning'
)
AND due_date > (CURRENT_DATE + INTERVAL '365 days')
)
);