17 lines
851 B
MySQL
17 lines
851 B
MySQL
|
|
-- Additive: distinguish explicit V5 billing choices without changing legacy approval defaults.
|
||
|
|
-- Expand the existing source check; preserve its expression and all historical rows.
|
||
|
|
DO $$
|
||
|
|
DECLARE existing_expression TEXT;
|
||
|
|
BEGIN
|
||
|
|
SELECT pg_get_expr(conbin, conrelid) INTO existing_expression
|
||
|
|
FROM pg_constraint
|
||
|
|
WHERE conrelid = 'tmodule_times'::regclass AND conname = 'tmodule_times_kilde_check';
|
||
|
|
IF existing_expression IS NULL THEN
|
||
|
|
existing_expression := 'kilde IN (''auto'', ''manuel'', ''api'')';
|
||
|
|
END IF;
|
||
|
|
IF POSITION('sag_v5' IN existing_expression) = 0 THEN
|
||
|
|
ALTER TABLE tmodule_times DROP CONSTRAINT IF EXISTS tmodule_times_kilde_check;
|
||
|
|
EXECUTE FORMAT('ALTER TABLE tmodule_times ADD CONSTRAINT tmodule_times_kilde_check CHECK ((%s) OR kilde = %L)', existing_expression, 'sag_v5');
|
||
|
|
END IF;
|
||
|
|
END $$;
|