added site_id, creator_id, last_modified_by_id, date_created, last_modified fields...
authorTony Mack <tmack@cs.princeton.edu>
Tue, 21 Oct 2008 19:12:13 +0000 (19:12 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Tue, 21 Oct 2008 19:12:13 +0000 (19:12 +0000)
planetlab4.sql

index b5ffb1b..e71c067 100644 (file)
@@ -348,6 +348,11 @@ CREATE TABLE conf_files (
     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
+    site_id integer NOT NULL REFERENCES sites,         -- Site identifier 
+    creator_id integer NOT NULL REFERENCES persons,  -- Person id of whoever created this file
+    last_modified_by_id integer NOT NULL REFERENCES persons,  -- Person id of whoever last updated this file
+    date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,  -- Date this file was created
+    last_modified timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP  -- Date this file was last modified
 ) WITH OIDS;
 
 CREATE TABLE conf_file_node (
@@ -372,6 +377,29 @@ array_accum(conf_file_id) AS conf_file_ids
 FROM conf_file_node
 GROUP BY node_id;
 
+
+CREATE TABLE conf_file_slice (
+    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);
+
+-- Slices linked to each configuration file
+CREATE 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 slice
+CREATE 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
@@ -1032,7 +1060,23 @@ FROM nodegroups;
 
 CREATE OR REPLACE VIEW view_conf_files AS
 SELECT
-conf_files.*,
+conf_files.conf_file_id,
+conf_files.enabled,
+conf_files.source,
+conf_files.dest,
+conf_files.file_permissions,
+conf_files.file_owner,
+conf_files.file_group,
+conf_files.preinstall_cmd,
+conf_files.postinstall_cmd,
+conf_files.error_cmd,
+conf_files.ignore_cmd_errors,
+conf_files.always_update,
+conf_files.site_id,
+conf_files.creator_id,
+conf_files.last_modified_by_id,
+CAST(date_part('epoch', conf_files.date_created) AS bigint) AS date_created,
+CAST(date_part('epoch', conf_files.last_modified) AS bigint) AS last_modified,
 COALESCE((SELECT node_ids FROM conf_file_nodes WHERE conf_file_nodes.conf_file_id = conf_files.conf_file_id), '{}') AS node_ids,
 COALESCE((SELECT nodegroup_ids FROM conf_file_nodegroups WHERE conf_file_nodegroups.conf_file_id = conf_files.conf_file_id), '{}') AS nodegroup_ids
 FROM conf_files;