From 3c6ac81e4c1efb285cba20f7efd9fefffb08abde Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 23 Nov 2010 16:04:43 +0100 Subject: [PATCH 1/1] get the down migration right --- PLC/SliceTags.py | 5 +++-- migrations/104-down-noderole.sql | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/PLC/SliceTags.py b/PLC/SliceTags.py index 78273ca..e5070fd 100644 --- a/PLC/SliceTags.py +++ b/PLC/SliceTags.py @@ -1,5 +1,6 @@ -# $Id$ -# $URL$ +# +# Thierry Parmentelat - INRIA +# from PLC.Faults import * from PLC.Parameter import Parameter from PLC.Filter import Filter diff --git a/migrations/104-down-noderole.sql b/migrations/104-down-noderole.sql index f3d5196..b8b4adb 100644 --- a/migrations/104-down-noderole.sql +++ b/migrations/104-down-noderole.sql @@ -1,20 +1,28 @@ --- reverting.... -DELETE from roles WHERE name='node'; - -- recreate the min_role_id column ALTER TABLE tag_types ADD COLUMN min_role_id integer REFERENCES roles; -- compute the highest role available for each tag_type and store it as min_role_id --- xxx todo +CREATE OR REPLACE VIEW tag_type_max_role_id AS +SELECT tag_type_id, max(role_id) from tag_type_role GROUP BY tag_type_id; + +-- tag_types that have at least one role in the new model get the max +UPDATE tag_types +SET min_role_id = tag_type_max_role_id.max +FROM tag_type_max_role_id WHERE tag_type_max_role_id.tag_type_id = tag_types.tag_type_id; ---- tmp - set to something so we can run down&up again -UPDATE tag_types SET min_role_id=10; -UPDATE tag_types SET min_role_id=20 WHERE tag_type_id%2=0; +-- the ones with no roles end up with min_role_id=10 +UPDATE tag_types +SET min_role_id=10 +WHERE min_role_id IS NULL; + +DELETE VIEW tag_type_max_role_id; DROP TABLE tag_type_role CASCADE; -- done by cascade --DROP VIEW view_tag_types; --DROP VIEW tag_type_roles; +DELETE from roles WHERE name='node'; + -------------------- UPDATE plc_db_version SET subversion = 103; -- 2.43.0