--
-- Copyright (C) 2006 The Trustees of Princeton University
--
--- $Id: planetlab4.sql,v 1.32 2006/11/13 16:23:11 thierry Exp $
+-- $Id: planetlab4.sql,v 1.36 2006/11/15 16:42:12 tmack Exp $
--
--------------------------------------------------------------------------------
initcond = '{}'
);
+--------------------------------------------------------------------------------
+-- Version
+--------------------------------------------------------------------------------
+
+--version
+CREATE TABLE plc_db_version (
+ version integer NOT NULL
+) WITH OIDS;
+
+INSERT INTO plc_db_version (version) VALUES (4);
+
--------------------------------------------------------------------------------
-- Accounts
--------------------------------------------------------------------------------
CREATE TABLE peer_node (
peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
node_id integer REFERENCES nodes NOT NULL, -- (Local) node identifier
- foreign_id integer NOT NULL, -- (Peer) node identifier
PRIMARY KEY (peer_id, node_id),
UNIQUE (node_id) -- Nodes can only be at one peer
) WITH OIDS;
-- Slices
CREATE TABLE slices (
slice_id serial PRIMARY KEY, -- Slice identifier
- site_id integer REFERENCES sites NOT NULL, -- Site identifier
+-- xxx temporarily remove the NOT NULL constraint
+ site_id integer REFERENCES sites, -- Site identifier
name text NOT NULL, -- Slice name
instantiation text REFERENCES slice_instantiations NOT NULL DEFAULT 'plc-instantiated', -- Slice state, e.g. plc-instantiated
url text, -- Project URL
max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
- creator_person_id integer REFERENCES persons NOT NULL, -- Creator
+-- xxx temporarily remove the NOT NULL constraint
+ creator_person_id integer REFERENCES persons, -- Creator
created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation date
expires timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP + '2 weeks', -- Expiration date
- is_deleted boolean NOT NULL DEFAULT false
+ deleted boolean NOT NULL DEFAULT false
) WITH OIDS;
-CREATE INDEX slices_site_id_idx ON slices (site_id) WHERE is_deleted IS false;
-CREATE INDEX slices_name_idx ON slices (name) WHERE is_deleted IS false;
+CREATE INDEX slices_site_id_idx ON slices (site_id) WHERE deleted IS false;
+CREATE INDEX slices_name_idx ON slices (name) WHERE deleted IS false;
-- Slivers
CREATE TABLE slice_node (
CREATE TABLE peer_slice (
peer_id integer REFERENCES peers NOT NULL, -- peer primary key
slice_id integer REFERENCES slices NOT NULL, -- node primary key
- foreign_id integer NOT NULL,
PRIMARY KEY (peer_id, slice_id)
) WITH OIDS;
CREATE INDEX peer_slice_peer_id_idx ON peer_slice (peer_id);
-CREATE INDEX peer_slice_slice_id_idx ON peer_slice (node_id);
+CREATE INDEX peer_slice_slice_id_idx ON peer_slice (slice_id);
CREATE VIEW peer_slices AS
SELECT peer_id,
INSERT INTO object_types (object_type) VALUES ('ConfFile');
INSERT INTO object_types (object_type) VALUES ('KeyType');
INSERT INTO object_types (object_type) VALUES ('Key');
+INSERT INTO object_types (object_type) VALUES ('Message');
INSERT INTO object_types (object_type) VALUES ('NetworkMethod');
INSERT INTO object_types (object_type) VALUES ('NetworkType');
INSERT INTO object_types (object_type) VALUES ('Network');
slices.description,
slices.max_nodes,
slices.creator_person_id,
-slices.is_deleted,
+slices.deleted,
CAST(date_part('epoch', slices.created) AS bigint) AS created,
CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
COALESCE(slice_nodes.node_ids, '{}') AS node_ids,
LEFT JOIN slice_nodes USING (slice_id)
LEFT JOIN slice_persons USING (slice_id)
LEFT JOIN slice_attributes USING (slice_id)
-WHERE peer_slice.peer_id IS NULL;
+WHERE peer_slice.peer_id IS NULL
+AND slices.site_id IS NOT NULL
+AND slices.creator_person_id IS NOT NULL;
CREATE VIEW view_foreign_slices AS
SELECT
slices.url,
slices.description,
slices.max_nodes,
-slices.is_deleted,
+slices.deleted,
CAST(date_part('epoch', slices.created) AS bigint) AS created,
-CAST(date_part('epoch', slices.expires) AS bigint) AS expires
+CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
+COALESCE(slice_nodes.node_ids, '{}') AS node_ids
FROM slices
LEFT JOIN peer_slice USING (slice_id)
+LEFT JOIN slice_nodes USING (slice_id)
WHERE peer_slice.peer_id IS NOT NULL;
--