rename IlinkType into LinkType as these types will be used for Nlinks as well
[plcapi.git] / planetlab5.sql
index 0fd11aa..fe4e562 100644 (file)
@@ -328,105 +328,7 @@ INNER JOIN node_tag_types USING (node_tag_type_id)
 INNER JOIN nodes USING (node_id);
 
 --------------------------------------------------------------------------------
--- Node groups
---------------------------------------------------------------------------------
-
--- Node groups
-CREATE TABLE nodegroups (
-    nodegroup_id serial PRIMARY KEY,                   -- Group identifier
-    groupname text UNIQUE NOT NULL,                    -- Group name 
-    node_tag_type_id integer REFERENCES node_tag_types,        -- node is in nodegroup if it has this tag defined
-    tagvalue text NOT NULL                             -- with this value attached
-) WITH OIDS;
-
--- xxx - first rough implem
-CREATE OR REPLACE VIEW nodegroup_node AS
-SELECT nodegroup_id, node_id 
-FROM node_tag_types 
-JOIN node_tag 
-USING (node_tag_type_id) 
-JOIN nodegroups 
-USING (node_tag_type_id,tagvalue);
-
-CREATE OR REPLACE VIEW nodegroup_nodes AS
-SELECT nodegroup_id,
-array_accum(node_id) AS node_ids
-FROM nodegroup_node
-GROUP BY nodegroup_id;
-
--- Node groups that each node is a member of
-CREATE OR REPLACE VIEW node_nodegroups AS
-SELECT node_id,
-array_accum(nodegroup_id) AS nodegroup_ids
-FROM nodegroup_node
-GROUP BY node_id;
-
---------------------------------------------------------------------------------
--- Node configuration files
---------------------------------------------------------------------------------
-
-CREATE TABLE conf_files (
-    conf_file_id serial PRIMARY KEY,                   -- Configuration file identifier
-    enabled bool NOT NULL DEFAULT true,                        -- Configuration file is active
-    source text NOT NULL,                              -- Relative path on the boot server
-                                                       -- where file can be downloaded
-    dest text NOT NULL,                                        -- Absolute path where file should be installed
-    file_permissions text NOT NULL DEFAULT '0644',     -- chmod(1) permissions
-    file_owner text NOT NULL DEFAULT 'root',           -- chown(1) owner
-    file_group text NOT NULL DEFAULT 'root',           -- chgrp(1) owner
-    preinstall_cmd text,                               -- Shell command to execute prior to installing
-    postinstall_cmd text,                              -- Shell command to execute after installing
-    error_cmd text,                                    -- Shell command to execute if any error occurs
-    ignore_cmd_errors bool NOT NULL DEFAULT false,     -- Install file anyway even if an error occurs
-    always_update bool NOT NULL DEFAULT false          -- Always attempt to install file even if unchanged
-) WITH OIDS;
-
-CREATE TABLE conf_file_node (
-    conf_file_id integer REFERENCES conf_files NOT NULL,       -- Configuration file identifier
-    node_id integer REFERENCES nodes NOT NULL,                 -- Node identifier
-    PRIMARY KEY (conf_file_id, node_id)
-);
-CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
-CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
-
--- Nodes linked to each configuration file
-CREATE OR REPLACE VIEW conf_file_nodes AS
-SELECT conf_file_id,
-array_accum(node_id) AS node_ids
-FROM conf_file_node
-GROUP BY conf_file_id;
-
--- Configuration files linked to each node
-CREATE OR REPLACE VIEW node_conf_files AS
-SELECT node_id,
-array_accum(conf_file_id) AS conf_file_ids
-FROM conf_file_node
-GROUP BY node_id;
-
-CREATE TABLE conf_file_nodegroup (
-    conf_file_id integer REFERENCES conf_files NOT NULL,       -- Configuration file identifier
-    nodegroup_id integer REFERENCES nodegroups NOT NULL,       -- Node group identifier
-    PRIMARY KEY (conf_file_id, nodegroup_id)
-);
-CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
-CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
-
--- Node groups linked to each configuration file
-CREATE OR REPLACE VIEW conf_file_nodegroups AS
-SELECT conf_file_id,
-array_accum(nodegroup_id) AS nodegroup_ids
-FROM conf_file_nodegroup
-GROUP BY conf_file_id;
-
--- Configuration files linked to each node group
-CREATE OR REPLACE VIEW nodegroup_conf_files AS
-SELECT nodegroup_id,
-array_accum(conf_file_id) AS conf_file_ids
-FROM conf_file_nodegroup
-GROUP BY nodegroup_id;
-
---------------------------------------------------------------------------------
--- Node network interfaces
+-- (network) interfaces
 --------------------------------------------------------------------------------
 
 -- Valid network addressing schemes
@@ -487,7 +389,7 @@ CREATE TABLE interface_setting_types (
     name text UNIQUE NOT NULL,                         -- Setting Name    
     description text,                                  -- Optional Description
     category text NOT NULL DEFAULT 'general',          -- Free text for grouping, e.g. Wifi, or whatever
-    min_role_id integer REFERENCES roles DEFAULT 10    -- If set, minimal role required
+    min_role_id integer REFERENCES roles DEFAULT 10    -- minimal role required
 ) WITH OIDS;
 
 CREATE TABLE interface_setting (
@@ -537,6 +439,144 @@ interfaces.hostname,
 COALESCE((SELECT interface_setting_ids FROM interface_settings WHERE interface_settings.interface_id = interfaces.interface_id), '{}') AS interface_setting_ids
 FROM interfaces;
 
+--------------------------------------------------------------------------------
+-- ilinks : links between interfaces
+--------------------------------------------------------------------------------
+CREATE TABLE link_types (
+       link_type_id serial PRIMARY KEY,                -- id
+       name text UNIQUE NOT NULL,                      -- link name
+       description text,                               -- optional description
+       min_role_id integer REFERENCES roles DEFAULT 10         -- minimal role required
+) WITH OIDS;
+
+CREATE TABLE ilink (
+       ilink_id serial PRIMARY KEY,                            -- id
+       link_type_id integer REFERENCES link_types,             -- id of the ilink type
+       src_interface_id integer REFERENCES interfaces not NULL,        -- id of src interface
+       dst_interface_id integer REFERENCES interfaces NOT NULL, -- id of dst interface
+       value text                                              -- optional value on the link
+) WITH OIDS;
+
+CREATE OR REPLACE VIEW view_ilinks AS
+SELECT * FROM link_types 
+INNER JOIN ilink USING (link_type_id);
+
+-- expose node_ids ???
+-- -- cannot mention the same table twice in a join ?
+-- -- CREATE OR REPLACE VIEW ilink_src_node AS 
+-- SELECT 
+-- ilink.link_type_id,
+-- ilink.src_interface_id,
+-- interfaces.node_id AS src_node_id,
+-- ilink.dst_interface_id
+-- FROM ilink 
+-- INNER JOIN interfaces ON ilink.src_interface_id = interfaces.interface_id;
+-- 
+-- CREATE OR REPLACE VIEW ilink_nodes AS
+-- SELECT 
+-- ilink_src_node.*,
+-- interfaces.node_id as dst_node_id
+-- FROM ilink_src_node
+-- INNER JOIN interfaces ON ilink_src_node.dst_interface_id = interfaces.interface_id;
+
+--------------------------------------------------------------------------------
+-- Node groups
+--------------------------------------------------------------------------------
+
+-- Node groups
+CREATE TABLE nodegroups (
+    nodegroup_id serial PRIMARY KEY,                   -- Group identifier
+    groupname text UNIQUE NOT NULL,                    -- Group name 
+    node_tag_type_id integer REFERENCES node_tag_types,        -- node is in nodegroup if it has this tag defined
+    tagvalue text NOT NULL                             -- with this value attached
+) WITH OIDS;
+
+-- xxx - first rough implem. similar to former semantics but might be slow
+CREATE OR REPLACE VIEW nodegroup_node AS
+SELECT nodegroup_id, node_id 
+FROM node_tag_types 
+JOIN node_tag 
+USING (node_tag_type_id) 
+JOIN nodegroups 
+USING (node_tag_type_id,tagvalue);
+
+CREATE OR REPLACE VIEW nodegroup_nodes AS
+SELECT nodegroup_id,
+array_accum(node_id) AS node_ids
+FROM nodegroup_node
+GROUP BY nodegroup_id;
+
+-- Node groups that each node is a member of
+CREATE OR REPLACE VIEW node_nodegroups AS
+SELECT node_id,
+array_accum(nodegroup_id) AS nodegroup_ids
+FROM nodegroup_node
+GROUP BY node_id;
+
+--------------------------------------------------------------------------------
+-- Node configuration files
+--------------------------------------------------------------------------------
+
+CREATE TABLE conf_files (
+    conf_file_id serial PRIMARY KEY,                   -- Configuration file identifier
+    enabled bool NOT NULL DEFAULT true,                        -- Configuration file is active
+    source text NOT NULL,                              -- Relative path on the boot server
+                                                       -- where file can be downloaded
+    dest text NOT NULL,                                        -- Absolute path where file should be installed
+    file_permissions text NOT NULL DEFAULT '0644',     -- chmod(1) permissions
+    file_owner text NOT NULL DEFAULT 'root',           -- chown(1) owner
+    file_group text NOT NULL DEFAULT 'root',           -- chgrp(1) owner
+    preinstall_cmd text,                               -- Shell command to execute prior to installing
+    postinstall_cmd text,                              -- Shell command to execute after installing
+    error_cmd text,                                    -- Shell command to execute if any error occurs
+    ignore_cmd_errors bool NOT NULL DEFAULT false,     -- Install file anyway even if an error occurs
+    always_update bool NOT NULL DEFAULT false          -- Always attempt to install file even if unchanged
+) WITH OIDS;
+
+CREATE TABLE conf_file_node (
+    conf_file_id integer REFERENCES conf_files NOT NULL,       -- Configuration file identifier
+    node_id integer REFERENCES nodes NOT NULL,                 -- Node identifier
+    PRIMARY KEY (conf_file_id, node_id)
+);
+CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
+CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
+
+-- Nodes linked to each configuration file
+CREATE OR REPLACE VIEW conf_file_nodes AS
+SELECT conf_file_id,
+array_accum(node_id) AS node_ids
+FROM conf_file_node
+GROUP BY conf_file_id;
+
+-- Configuration files linked to each node
+CREATE OR REPLACE VIEW node_conf_files AS
+SELECT node_id,
+array_accum(conf_file_id) AS conf_file_ids
+FROM conf_file_node
+GROUP BY node_id;
+
+CREATE TABLE conf_file_nodegroup (
+    conf_file_id integer REFERENCES conf_files NOT NULL,       -- Configuration file identifier
+    nodegroup_id integer REFERENCES nodegroups NOT NULL,       -- Node group identifier
+    PRIMARY KEY (conf_file_id, nodegroup_id)
+);
+CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
+CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
+
+-- Node groups linked to each configuration file
+CREATE OR REPLACE VIEW conf_file_nodegroups AS
+SELECT conf_file_id,
+array_accum(nodegroup_id) AS nodegroup_ids
+FROM conf_file_nodegroup
+GROUP BY conf_file_id;
+
+-- Configuration files linked to each node group
+CREATE OR REPLACE VIEW nodegroup_conf_files AS
+SELECT nodegroup_id,
+array_accum(conf_file_id) AS conf_file_ids
+FROM conf_file_nodegroup
+GROUP BY nodegroup_id;
+
 --------------------------------------------------------------------------------
 -- Power control units (PCUs)
 --------------------------------------------------------------------------------