Peer object now has hrn_root
[plcapi.git] / migrations / v4-to-v5 / migrate.sql
index 6f36acb..99b72bc 100644 (file)
@@ -3,6 +3,8 @@
 -- $Id$
 --
 -- this is part of the script to migrate from 4.2 to 5.0
+-- 
+-- most of the renamings have taken place already when this script is invoked
 --
 
 ----------------------------------------
@@ -51,7 +53,7 @@ DROP VIEW node_slices CASCADE;
 DROP VIEW node_slices_whitelist CASCADE;
 DROP VIEW nodegroup_conf_files CASCADE;
 DROP VIEW nodegroup_nodes CASCADE;
-DROP VIEW interface_settings CASCADE;
+DROP VIEW interface_tags CASCADE;
 DROP VIEW pcu_nodes CASCADE;
 DROP VIEW pcu_protocol_types CASCADE;
 DROP VIEW peer_keys CASCADE;
@@ -69,7 +71,7 @@ DROP VIEW site_nodes CASCADE;
 DROP VIEW site_pcus CASCADE;
 DROP VIEW site_persons CASCADE;
 DROP VIEW site_slices CASCADE;
-DROP VIEW slice_attributes CASCADE;
+DROP VIEW slice_tags CASCADE;
 DROP VIEW slice_nodes CASCADE;
 DROP VIEW slice_persons CASCADE;
 DROP VIEW slivers CASCADE;
@@ -80,7 +82,7 @@ DROP VIEW view_event_objects CASCADE;
 -- caught by some previous cascade -- DROP VIEW view_events CASCADE;
 DROP VIEW view_keys CASCADE;
 -- caught by some previous cascade -- DROP VIEW view_nodegroups CASCADE;
-DROP VIEW view_interface_settings CASCADE;
+DROP VIEW view_interface_tags CASCADE;
 -- caught by some previous cascade -- DROP VIEW view_interfaces CASCADE;
 -- caught by some previous cascade -- DROP VIEW view_nodes CASCADE;
 -- caught by some previous cascade -- DROP VIEW view_pcu_types CASCADE;
@@ -89,7 +91,7 @@ DROP VIEW view_interface_settings CASCADE;
 -- caught by some previous cascade -- DROP VIEW view_persons CASCADE;
 DROP VIEW view_sessions CASCADE;
 -- caught by some previous cascade -- DROP VIEW view_sites CASCADE;
-DROP VIEW view_slice_attributes CASCADE;
+DROP VIEW view_slice_tags CASCADE;
 -- caught by some previous cascade -- DROP VIEW view_slices CASCADE;
 
 -- shows in logfile
@@ -99,6 +101,17 @@ select * from mgn_all_views;
 drop view mgn_all_views;
 drop function mgn_drop_all_views ();
 
+----------------------------------------
+-- peers
+----------------------------------------
+ALTER TABLE peers ADD COLUMN shortname TEXT;
+ALTER TABLE peers ADD COLUMN hrn_root TEXT;
+
+----------------------------------------
+-- nodes
+----------------------------------------
+ALTER TABLE nodes ADD COLUMN node_type TEXT NOT NULL DEFAULT 'regular';
+
 ----------------------------------------
 -- tag types
 ----------------------------------------
@@ -111,41 +124,41 @@ ALTER TABLE tag_types RENAME COLUMN name TO tagname;
 --- former slice_attribute_types had no 'category'
 ALTER TABLE tag_types ADD COLUMN category TEXT NOT NULL DEFAULT 'slice/legacy';
 
---- append in tag_types the contents of nodenetwork_setting_types
+--- append in tag_types the contents of former nodenetwork_setting_types
 INSERT INTO tag_types (tagname,description,min_role_id,category) 
-       SELECT name,description,min_role_id,'interface/legacy' FROM interface_setting_types;
+       SELECT name,description,min_role_id,'interface/legacy' FROM interface_tag_types;
 
 ---------- interface settings
 
---- former nodenetwork_setting_type_id are now renumbered, need to fix interface_setting accordingly
+--- former nodenetwork_setting_type_id are now renumbered, need to fix interface_tag accordingly
 
 -- old_index -> new_index relation
 CREATE OR REPLACE VIEW mgn_setting_renumber AS
    SELECT 
-      interface_setting_types.interface_setting_type_id AS old_index,  
+      interface_tag_types.interface_tag_type_id AS old_index,  
       tag_types.tag_type_id AS new_index 
    FROM 
-      interface_setting_types INNER JOIN tag_types  
-      ON interface_setting_types.name = tag_types.tagname;
+      interface_tag_types INNER JOIN tag_types  
+      ON interface_tag_types.name = tag_types.tagname;
 
--- need to temporarily drop constraint on interface_setting_type_id
-ALTER TABLE interface_setting DROP CONSTRAINT interface_setting_interface_setting_type_id_fkey;
+-- need to temporarily drop constraint on interface_tag_type_id
+ALTER TABLE interface_tag DROP CONSTRAINT interface_tag_interface_tag_type_id_fkey;
 
 -- do the transcoding
-UPDATE interface_settin
-   SET interface_setting_type_id = 
-      (select new_index from mgn_setting_renumber where old_index=interface_setting_type_id);
+UPDATE interface_ta
+   SET interface_tag_type_id = 
+      (select new_index from mgn_setting_renumber where old_index=interface_tag_type_id);
 
 -- alter column name to reflect change
-ALTER TABLE interface_setting RENAME interface_setting_type_id TO tag_type_id;
+ALTER TABLE interface_tag RENAME interface_tag_type_id TO tag_type_id;
 
--- add contraint again
-ALTER TABLE interface_setting ADD CONSTRAINT interface_setting_tag_type_id_fkey 
+-- add constraint again
+ALTER TABLE interface_tag ADD CONSTRAINT interface_tag_tag_type_id_fkey 
     FOREIGN KEY (tag_type_id) references tag_types(tag_type_id) ;
 
--- drop former interface_setting_types altogether
+-- drop former interface_tag_types altogether
 drop view mgn_setting_renumber;
-drop table interface_setting_types;
+drop table interface_tag_types;
 
 ---------- node tags
 
@@ -153,7 +166,7 @@ CREATE TABLE node_tag (
     node_tag_id serial PRIMARY KEY,                    -- ID
     node_id integer REFERENCES nodes NOT NULL,         -- node id
     tag_type_id integer REFERENCES tag_types,          -- tag type id
-    tagvalue text                                      -- value attached
+    value text                                         -- value attached
 ) WITH OIDS;
 
 
@@ -175,7 +188,7 @@ CREATE TABLE ilink (
 ---------- nodegroups table - start
 -- nodegroup_id is preserved for conf_files and other references
 -- former nodegroups table was (nodegroup_id,name,description)
--- new table is        now            (nodegroup_id, groupname, tag_type_id, tagvalue)
+-- new table is        now            (nodegroup_id, groupname, tag_type_id, value)
 
 -- rename column
 ALTER TABLE nodegroups RENAME name TO groupname;
@@ -194,23 +207,23 @@ INSERT INTO tag_types (tagname)
 ALTER TABLE nodegroups DROP COLUMN description;
 
 ---------- set the right tags so as to recover former nodegroups
-INSERT INTO node_tag (node_id, tag_type_id, tagvalue)
-   SELECT node_id, tag_type_id, tagvalue FROM
+INSERT INTO node_tag (node_id, tag_type_id, value)
+   SELECT node_id, tag_type_id, value FROM
       nodegroup_node LEFT JOIN nodegroups USING (nodegroup_id) 
          INNER JOIN mgn_site_nodegroup USING (groupname)
            LEFT JOIN tag_types using (tagname); 
 
 ---------- nodegroups table - conclusion
 ALTER TABLE nodegroups ADD COLUMN tag_type_id INTEGER;
-ALTER TABLE nodegroups ADD COLUMN tagvalue TEXT;
+ALTER TABLE nodegroups ADD COLUMN value TEXT;
 
 CREATE OR REPLACE VIEW mgn_nodegroups AS
-   SELECT groupname, tag_types.tag_type_id, mgn_site_nodegroup.tagvalue 
+   SELECT groupname, tag_types.tag_type_id, mgn_site_nodegroup.value 
       FROM nodegroups INNER JOIN mgn_site_nodegroup USING (groupname) 
          INNER JOIN tag_types USING (tagname);
 
 UPDATE nodegroups SET tag_type_id = (SELECT tag_type_id FROM mgn_nodegroups WHERE nodegroups.groupname=mgn_nodegroups.groupname);
-UPDATE nodegroups SET tagvalue = (SELECT tagvalue FROM mgn_nodegroups WHERE nodegroups.groupname=mgn_nodegroups.groupname);
+UPDATE nodegroups SET value = (SELECT value FROM mgn_nodegroups WHERE nodegroups.groupname=mgn_nodegroups.groupname);
 
 -- install corresponding constraints
 ALTER TABLE nodegroups ADD CONSTRAINT nodegroups_tag_type_id_fkey
@@ -227,30 +240,23 @@ drop table nodegroup_node;
 ----------------------------------------
 -- boot states
 ----------------------------------------
-INSERT INTO boot_states (boot_state) 
-       VALUES ('safeboot'), ('failboot'), ('disabled'), ('install'), ('reinstall');
-
--- xxx need checking 
---
--- boot          boot
--- dbg           safeboot ?
--- diag          failboot ?
--- disable       disabled
--- inst          install
--- rins          reinstall
--- new           reinstall ?
--- rcnf              failboot ?
-
-
-UPDATE nodes SET boot_state='safeboot' WHERE boot_state='dbg';
-UPDATE nodes SET boot_state='failboot' WHERE boot_state='diag';
+-- create new ones
+INSERT INTO boot_states (boot_state) VALUES ('safeboot');
+INSERT INTO boot_states (boot_state) VALUES ('failboot');
+INSERT INTO boot_states (boot_state) VALUES ('disabled');
+INSERT INTO boot_states (boot_state) VALUES ('install');
+INSERT INTO boot_states (boot_state) VALUES ('reinstall');
+
+-- map old ones
+UPDATE nodes SET boot_state='failboot' WHERE boot_state='dbg';
+UPDATE nodes SET boot_state='safeboot' WHERE boot_state='diag';
 UPDATE nodes SET boot_state='disabled' WHERE boot_state='disable';
 UPDATE nodes SET boot_state='install' WHERE boot_state='inst';
 UPDATE nodes SET boot_state='reinstall' WHERE boot_state='rins';
 UPDATE nodes SET boot_state='reinstall' WHERE boot_state='new';
 UPDATE nodes SET boot_state='failboot' WHERE boot_state='rcnf';
 
--- one-by-one is safer
+-- delete old ones
 DELETE FROM boot_states WHERE boot_state='dbg';
 DELETE FROM boot_states WHERE boot_state='diag';
 DELETE FROM boot_states WHERE boot_state='disable';