remove PLC.Debug.log, use PLC.Logger.logger instead
[plcapi.git] / migrations / 102-down-isvalid.sql
1 ALTER TABLE nodes DROP COLUMN last_download; 
2 ALTER TABLE nodes DROP COLUMN last_pcu_reboot; 
3 ALTER TABLE nodes DROP COLUMN last_pcu_confirmation;
4
5 ALTER TABLE pcus DROP COLUMN last_updated timestamp without time zone;
6
7 ALTER TABLE interfaces DROP COLUMN last_updated timestamp without time zone;
8
9 DROP VIEW view_nodes;
10 CREATE OR REPLACE VIEW view_nodes AS
11 SELECT
12 nodes.node_id,
13 nodes.node_type,
14 nodes.hostname,
15 nodes.site_id,
16 nodes.boot_state,
17 nodes.run_level,
18 nodes.deleted,
19 nodes.model,
20 nodes.boot_nonce,
21 nodes.version,
22 nodes.verified,
23 nodes.ssh_rsa_key,
24 nodes.key,
25 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
26 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
27 CAST(date_part('epoch', nodes.last_contact) AS bigint) AS last_contact,  
28 peer_node.peer_id,
29 peer_node.peer_node_id,
30 COALESCE((SELECT interface_ids FROM node_interfaces 
31                  WHERE node_interfaces.node_id = nodes.node_id), '{}') 
32 AS interface_ids,
33 COALESCE((SELECT nodegroup_ids FROM node_nodegroups 
34                  WHERE node_nodegroups.node_id = nodes.node_id), '{}') 
35 AS nodegroup_ids,
36 COALESCE((SELECT slice_ids FROM node_slices 
37                  WHERE node_slices.node_id = nodes.node_id), '{}') 
38 AS slice_ids,
39 COALESCE((SELECT slice_ids_whitelist FROM node_slices_whitelist 
40                  WHERE node_slices_whitelist.node_id = nodes.node_id), '{}') 
41 AS slice_ids_whitelist,
42 COALESCE((SELECT pcu_ids FROM node_pcus 
43                  WHERE node_pcus.node_id = nodes.node_id), '{}') 
44 AS pcu_ids,
45 COALESCE((SELECT ports FROM node_pcus
46                  WHERE node_pcus.node_id = nodes.node_id), '{}') 
47 AS ports,
48 COALESCE((SELECT conf_file_ids FROM node_conf_files
49                  WHERE node_conf_files.node_id = nodes.node_id), '{}') 
50 AS conf_file_ids,
51 COALESCE((SELECT node_tag_ids FROM node_tags 
52                  WHERE node_tags.node_id = nodes.node_id), '{}') 
53 AS node_tag_ids,
54 node_session.session_id AS session
55 FROM nodes
56 LEFT JOIN peer_node USING (node_id)
57 LEFT JOIN node_session USING (node_id);
58
59 DROP VIEW view_pcus;
60 CREATE OR REPLACE VIEW view_pcus AS
61 SELECT
62 pcus.*,
63 COALESCE((SELECT node_ids FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS node_ids,
64 COALESCE((SELECT ports FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS ports
65 FROM pcus;
66
67
68 DROP VIEW view_interfaces;
69 CREATE OR REPLACE VIEW view_interfaces AS
70 SELECT
71 interfaces.interface_id,
72 interfaces.node_id,
73 interfaces.is_primary,
74 interfaces.type,
75 interfaces.method,
76 interfaces.ip,
77 interfaces.mac,
78 interfaces.gateway,
79 interfaces.network,
80 interfaces.broadcast,
81 interfaces.netmask,
82 interfaces.dns1,
83 interfaces.dns2,
84 interfaces.bwlimit,
85 interfaces.hostname,
86 COALESCE((SELECT interface_tag_ids FROM interface_tags WHERE interface_tags.interface_id = interfaces.interface_id), '{}') AS interface_tag_ids
87 FROM interfaces;
88