bmc_hub/migrations/1052_sag_status_constraint_compatibility.sql

25 lines
882 B
MySQL
Raw Normal View History

2026-09-25 11:33:53 +02:00
-- Repair installations that still have the legacy sag_sager status constraint.
-- The case module manages its allowed statuses in settings; the database only
-- guarantees that a case status is present.
DO $$
DECLARE
constraint_row RECORD;
BEGIN
FOR constraint_row IN
SELECT c.conname
FROM pg_constraint c
JOIN pg_class t ON t.oid = c.conrelid
JOIN pg_namespace n ON n.oid = t.relnamespace
WHERE n.nspname = 'public'
AND t.relname = 'sag_sager'
AND c.contype = 'c'
AND c.conname IN ('sag_sager_status_check', 'sag_sager_status_nonempty_check')
LOOP
EXECUTE format('ALTER TABLE public.sag_sager DROP CONSTRAINT IF EXISTS %I', constraint_row.conname);
END LOOP;
END $$;
ALTER TABLE public.sag_sager
ADD CONSTRAINT sag_sager_status_nonempty_check
CHECK (length(trim(status)) > 0);