Merge remote-tracking branch 'origin/pycurl' into planetlab-4_0-branch
[plcapi.git] / migrations / 008-up-import-aug-2007.sql
1 --
2 -- migration 008
3 -- import from Princeton codebase on august 2007 28
4 -- slice instantiation 'nm-controller'
5 -- * white lists
6 -- 
7
8 INSERT INTO slice_instantiations (instantiation) VALUES ('nm-controller'); -- NM Controller
9
10 --------------------------------------------------------------------------------
11 -- Slice whitelist
12 --------------------------------------------------------------------------------
13 -- slice whitelist on nodes
14 CREATE TABLE node_slice_whitelist (
15     node_id integer REFERENCES nodes NOT NULL, -- Node id of whitelist
16     slice_id integer REFERENCES slices NOT NULL, -- Slice id thats allowd on this node
17     PRIMARY KEY (node_id, slice_id)
18 ) WITH OIDS;
19 CREATE INDEX node_slice_whitelist_node_id_idx ON node_slice_whitelist (node_id);
20 CREATE INDEX node_slice_whitelist_slice_id_idx ON node_slice_whitelist (slice_id);
21
22 -- Slices on each node
23 CREATE VIEW node_slices_whitelist AS
24 SELECT node_id,
25 array_accum(slice_id) AS slice_ids_whitelist
26 FROM node_slice_whitelist
27 GROUP BY node_id;
28
29 DROP VIEW view_nodes;
30
31
32 CREATE OR REPLACE VIEW view_nodes AS
33 SELECT
34 nodes.node_id,
35 nodes.hostname,
36 nodes.site_id,
37 nodes.boot_state,
38 nodes.deleted,
39 nodes.model,
40 nodes.boot_nonce,
41 nodes.version,
42 nodes.ssh_rsa_key,
43 nodes.key,
44 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
45 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
46 CAST(date_part('epoch', nodes.last_contact) AS bigint) AS last_contact,  
47 peer_node.peer_id,
48 peer_node.peer_node_id,
49 COALESCE((SELECT nodenetwork_ids FROM node_nodenetworks WHERE node_nodenetworks.node_id = nodes.node_id), '{}') AS nodenetwork_ids,
50 COALESCE((SELECT nodegroup_ids FROM node_nodegroups WHERE node_nodegroups.node_id = nodes.node_id), '{}') AS nodegroup_ids,
51 COALESCE((SELECT slice_ids FROM node_slices WHERE node_slices.node_id = nodes.node_id), '{}') AS slice_ids,
52 COALESCE((SELECT slice_ids_whitelist FROM node_slices_whitelist WHERE node_slices_whitelist.node_id = nodes.node_id), '{}') AS slice_ids_whitelist,
53 COALESCE((SELECT pcu_ids FROM node_pcus WHERE node_pcus.node_id = nodes.node_id), '{}') AS pcu_ids,
54 COALESCE((SELECT ports FROM node_pcus WHERE node_pcus.node_id = nodes.node_id), '{}') AS ports,
55 COALESCE((SELECT conf_file_ids FROM node_conf_files WHERE node_conf_files.node_id = nodes.node_id), '{}') AS conf_file_ids,
56 node_session.session_id AS session
57 FROM nodes
58 LEFT JOIN peer_node USING (node_id)
59 LEFT JOIN node_session USING (node_id);
60
61 ---------- bump subversion
62
63 UPDATE plc_db_version SET subversion = 8;
64 SELECT subversion from plc_db_version;