Skip to content
Snippets Groups Projects
Commit 30dc8ae9 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-725: initial database trigger for blocking illegal subtask state...

TMSS-725: initial database trigger for blocking illegal subtask state transitions. TODO: add all transitions according to design
parent 0f25f542
No related branches found
No related tags found
1 merge request!414Resolve TMSS-725
...@@ -14,9 +14,24 @@ class Migration(migrations.Migration): ...@@ -14,9 +14,24 @@ class Migration(migrations.Migration):
('tmssapp', '0001_initial'), ('tmssapp', '0001_initial'),
] ]
# Start SubTask id with 2 000 000 to avoid overlap with 'old' (test/production) OTDB
operations = [ migrations.RunSQL('ALTER SEQUENCE tmssapp_SubTask_id_seq RESTART WITH 2000000;'), operations = [ migrations.RunSQL('ALTER SEQUENCE tmssapp_SubTask_id_seq RESTART WITH 2000000;'), # Start SubTask id with 2 000 000 to avoid overlap with 'old' (test/production) OTDB
migrations.RunPython(populate_choices), migrations.RunPython(populate_choices), # poppulates the "fixed" enums, with amongst others the subtask_states which are used next in the trigger
migrations.RunSQL("CREATE OR REPLACE FUNCTION tmssapp_check_subtask_state_transition() \
RETURNS trigger AS \
$BODY$ \
BEGIN \
IF OLD.state_id='defining' AND NEW.state_id != 'defined' THEN \
RAISE EXCEPTION 'ILLEGAL SUBTASK STATE TRANSITION FROM % TO %', OLD.state_id, NEW.state_id; \
END IF; \
RETURN NEW; \
END; \
$BODY$ \
LANGUAGE plpgsql VOLATILE; \
DROP TRIGGER IF EXISTS tmssapp_trigger_on_check_subtask_state_transition ON tmssapp_SubTask ; \
CREATE TRIGGER tmssapp_trigger_on_check_subtask_state_transition \
AFTER UPDATE ON tmssapp_SubTask \
FOR EACH ROW EXECUTE PROCEDURE tmssapp_check_subtask_state_transition();"),
migrations.RunPython(populate_settings), migrations.RunPython(populate_settings),
migrations.RunPython(populate_misc), migrations.RunPython(populate_misc),
migrations.RunPython(populate_resources), migrations.RunPython(populate_resources),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment