2 -- PlanetLab Central database schema
3 -- Version 4, PostgreSQL
5 -- Aaron Klingaman <alk@cs.princeton.edu>
6 -- Reid Moran <rmoran@cs.princeton.edu>
7 -- Mark Huang <mlhuang@cs.princeton.edu>
8 -- Tony Mack <tmack@cs.princeton.edu>
10 -- Copyright (C) 2006 The Trustees of Princeton University
12 -- $Id: planetlab4.sql,v 1.66 2007/01/29 20:13:12 mlhuang Exp $
15 --------------------------------------------------------------------------------
16 -- Aggregates and store procedures
17 --------------------------------------------------------------------------------
19 -- Like MySQL GROUP_CONCAT(), this function aggregates values into a
21 CREATE AGGREGATE array_accum (
23 basetype = anyelement,
28 --------------------------------------------------------------------------------
30 --------------------------------------------------------------------------------
33 CREATE TABLE plc_db_version (
34 version integer NOT NULL
37 INSERT INTO plc_db_version (version) VALUES (4);
39 --------------------------------------------------------------------------------
41 --------------------------------------------------------------------------------
44 CREATE TABLE persons (
46 person_id serial PRIMARY KEY, -- Account identifier
47 email text NOT NULL, -- E-mail address
48 first_name text NOT NULL, -- First name
49 last_name text NOT NULL, -- Last name
50 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
51 enabled boolean NOT NULL DEFAULT false, -- Has been disabled
54 password text NOT NULL DEFAULT 'nopass', -- Password (md5crypted)
55 verification_key text, -- Reset password key
56 verification_expires timestamp without time zone,
59 title text, -- Honorific
60 phone text, -- Telephone number
61 url text, -- Home page
62 bio text, -- Biography
65 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
66 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
68 CREATE INDEX persons_email_idx ON persons (email) WHERE deleted IS false;
70 --------------------------------------------------------------------------------
72 --------------------------------------------------------------------------------
77 site_id serial PRIMARY KEY, -- Site identifier
78 login_base text NOT NULL, -- Site slice prefix
79 name text NOT NULL, -- Site name
80 abbreviated_name text NOT NULL, -- Site abbreviated name
81 enabled boolean NOT NULL Default true, -- Is this site enabled
82 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
83 is_public boolean NOT NULL DEFAULT true, -- Shows up in public lists
84 max_slices integer NOT NULL DEFAULT 0, -- Maximum number of slices
85 max_slivers integer NOT NULL DEFAULT 1000, -- Maximum number of instantiated slivers
93 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
94 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
96 CREATE INDEX sites_login_base_idx ON sites (login_base) WHERE deleted IS false;
98 -- Account site membership
99 CREATE TABLE person_site (
100 person_id integer REFERENCES persons NOT NULL, -- Account identifier
101 site_id integer REFERENCES sites NOT NULL, -- Site identifier
102 is_primary boolean NOT NULL DEFAULT false, -- Is the primary site for this account
103 PRIMARY KEY (person_id, site_id)
105 CREATE INDEX person_site_person_id_idx ON person_site (person_id);
106 CREATE INDEX person_site_site_id_idx ON person_site (site_id);
108 -- Ordered by primary site first
109 CREATE VIEW person_site_ordered AS
110 SELECT person_id, site_id
112 ORDER BY is_primary DESC;
114 -- Sites that each person is a member of
115 CREATE VIEW person_sites AS
117 array_accum(site_id) AS site_ids
118 FROM person_site_ordered
121 -- Accounts at each site
122 CREATE VIEW site_persons AS
124 array_accum(person_id) AS person_ids
128 --------------------------------------------------------------------------------
130 --------------------------------------------------------------------------------
132 CREATE TABLE address_types (
133 address_type_id serial PRIMARY KEY, -- Address type identifier
134 name text UNIQUE NOT NULL, -- Address type
135 description text -- Address type description
138 INSERT INTO address_types (name) VALUES ('Personal');
139 INSERT INTO address_types (name) VALUES ('Shipping');
140 -- XXX Used to be Site
141 INSERT INTO address_types (name) VALUES ('Billing');
144 CREATE TABLE addresses (
145 address_id serial PRIMARY KEY, -- Address identifier
146 line1 text NOT NULL, -- Address line 1
147 line2 text, -- Address line 2
148 line3 text, -- Address line 3
149 city text NOT NULL, -- City
150 state text NOT NULL, -- State or province
151 postalcode text NOT NULL, -- Postal code
152 country text NOT NULL -- Country
155 -- Each mailing address can be one of several types
156 CREATE TABLE address_address_type (
157 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
158 address_type_id integer REFERENCES address_types NOT NULL, -- Address type
159 PRIMARY KEY (address_id, address_type_id)
161 CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
162 CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);
164 CREATE VIEW address_address_types AS
166 array_accum(address_type_id) AS address_type_ids,
167 array_accum(address_types.name) AS address_types
168 FROM address_address_type
169 LEFT JOIN address_types USING (address_type_id)
172 CREATE TABLE site_address (
173 site_id integer REFERENCES sites NOT NULL, -- Site identifier
174 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
175 PRIMARY KEY (site_id, address_id)
177 CREATE INDEX site_address_site_id_idx ON site_address (site_id);
178 CREATE INDEX site_address_address_id_idx ON site_address (address_id);
180 CREATE VIEW site_addresses AS
182 array_accum(address_id) AS address_ids
186 --------------------------------------------------------------------------------
187 -- Authentication Keys
188 --------------------------------------------------------------------------------
191 CREATE TABLE key_types (
192 key_type text PRIMARY KEY -- Key type
194 INSERT INTO key_types (key_type) VALUES ('ssh');
196 -- Authentication keys
198 key_id serial PRIMARY KEY, -- Key identifier
199 key_type text REFERENCES key_types NOT NULL, -- Key type
200 key text NOT NULL, -- Key material
201 is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
204 -- Account authentication key(s)
205 CREATE TABLE person_key (
206 key_id integer REFERENCES keys PRIMARY KEY, -- Key identifier
207 person_id integer REFERENCES persons NOT NULL -- Account identifier
209 CREATE INDEX person_key_person_id_idx ON person_key (person_id);
211 CREATE VIEW person_keys AS
213 array_accum(key_id) AS key_ids
217 --------------------------------------------------------------------------------
219 --------------------------------------------------------------------------------
221 -- Valid account roles
223 role_id integer PRIMARY KEY, -- Role identifier
224 name text UNIQUE NOT NULL -- Role symbolic name
226 INSERT INTO roles (role_id, name) VALUES (10, 'admin');
227 INSERT INTO roles (role_id, name) VALUES (20, 'pi');
228 INSERT INTO roles (role_id, name) VALUES (30, 'user');
229 INSERT INTO roles (role_id, name) VALUES (40, 'tech');
231 CREATE TABLE person_role (
232 person_id integer REFERENCES persons NOT NULL, -- Account identifier
233 role_id integer REFERENCES roles NOT NULL, -- Role identifier
234 PRIMARY KEY (person_id, role_id)
236 CREATE INDEX person_role_person_id_idx ON person_role (person_id);
239 CREATE VIEW person_roles AS
241 array_accum(role_id) AS role_ids,
242 array_accum(roles.name) AS roles
244 LEFT JOIN roles USING (role_id)
247 --------------------------------------------------------------------------------
249 --------------------------------------------------------------------------------
251 -- Valid node boot states
252 CREATE TABLE boot_states (
253 boot_state text PRIMARY KEY
255 INSERT INTO boot_states (boot_state) VALUES ('boot');
256 INSERT INTO boot_states (boot_state) VALUES ('dbg');
257 INSERT INTO boot_states (boot_state) VALUES ('inst');
258 INSERT INTO boot_states (boot_state) VALUES ('rins');
259 INSERT INTO boot_states (boot_state) VALUES ('rcnf');
260 INSERT INTO boot_states (boot_state) VALUES ('new');
265 node_id serial PRIMARY KEY, -- Node identifier
266 hostname text NOT NULL, -- Node hostname
267 site_id integer REFERENCES sites NOT NULL, -- At which site
269 boot_state text REFERENCES boot_states NOT NULL DEFAULT 'inst', -- Node boot state
270 deleted boolean NOT NULL DEFAULT false, -- Is deleted
273 model text, -- Hardware make and model
274 boot_nonce text, -- Random nonce updated by Boot Manager
275 version text, -- Boot CD version string updated by Boot Manager
276 ssh_rsa_key text, -- SSH host key updated by Boot Manager
277 key text, -- Node key generated by API when configuration file is downloaded
280 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
281 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
283 CREATE INDEX nodes_hostname_idx ON nodes (hostname) WHERE deleted IS false;
284 CREATE INDEX nodes_site_id_idx ON nodes (site_id) WHERE deleted IS false;
286 -- Nodes at each site
287 CREATE VIEW site_nodes AS
289 array_accum(node_id) AS node_ids
293 --------------------------------------------------------------------------------
295 --------------------------------------------------------------------------------
298 CREATE TABLE nodegroups (
299 nodegroup_id serial PRIMARY KEY, -- Group identifier
300 name text UNIQUE NOT NULL, -- Group name
301 description text -- Group description
304 -- Node group membership
305 CREATE TABLE nodegroup_node (
306 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Group identifier
307 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
308 PRIMARY KEY (nodegroup_id, node_id)
310 CREATE INDEX nodegroup_node_nodegroup_id_idx ON nodegroup_node (nodegroup_id);
311 CREATE INDEX nodegroup_node_node_id_idx ON nodegroup_node (node_id);
313 -- Nodes in each node group
314 CREATE VIEW nodegroup_nodes AS
316 array_accum(node_id) AS node_ids
318 GROUP BY nodegroup_id;
320 -- Node groups that each node is a member of
321 CREATE VIEW node_nodegroups AS
323 array_accum(nodegroup_id) AS nodegroup_ids
327 --------------------------------------------------------------------------------
328 -- Node configuration files
329 --------------------------------------------------------------------------------
331 CREATE TABLE conf_files (
332 conf_file_id serial PRIMARY KEY, -- Configuration file identifier
333 enabled bool NOT NULL DEFAULT true, -- Configuration file is active
334 source text NOT NULL, -- Relative path on the boot server where file can be downloaded
335 dest text NOT NULL, -- Absolute path where file should be installed
336 file_permissions text NOT NULL DEFAULT '0644', -- chmod(1) permissions
337 file_owner text NOT NULL DEFAULT 'root', -- chown(1) owner
338 file_group text NOT NULL DEFAULT 'root', -- chgrp(1) owner
339 preinstall_cmd text, -- Shell command to execute prior to installing
340 postinstall_cmd text, -- Shell command to execute after installing
341 error_cmd text, -- Shell command to execute if any error occurs
342 ignore_cmd_errors bool NOT NULL DEFAULT false, -- Install file anyway even if an error occurs
343 always_update bool NOT NULL DEFAULT false -- Always attempt to install file even if unchanged
346 CREATE TABLE conf_file_node (
347 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
348 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
349 PRIMARY KEY (conf_file_id, node_id)
351 CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
352 CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
354 -- Nodes linked to each configuration file
355 CREATE VIEW conf_file_nodes AS
357 array_accum(node_id) AS node_ids
359 GROUP BY conf_file_id;
361 -- Configuration files linked to each node
362 CREATE VIEW node_conf_files AS
364 array_accum(conf_file_id) AS conf_file_ids
368 CREATE TABLE conf_file_nodegroup (
369 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
370 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Node group identifier
371 PRIMARY KEY (conf_file_id, nodegroup_id)
373 CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
374 CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
376 -- Node groups linked to each configuration file
377 CREATE VIEW conf_file_nodegroups AS
379 array_accum(nodegroup_id) AS nodegroup_ids
380 FROM conf_file_nodegroup
381 GROUP BY conf_file_id;
383 -- Configuration files linked to each node group
384 CREATE VIEW nodegroup_conf_files AS
386 array_accum(conf_file_id) AS conf_file_ids
387 FROM conf_file_nodegroup
388 GROUP BY nodegroup_id;
390 --------------------------------------------------------------------------------
391 -- Node network interfaces
392 --------------------------------------------------------------------------------
394 -- Valid network addressing schemes
395 CREATE TABLE network_types (
396 type text PRIMARY KEY -- Addressing scheme
398 INSERT INTO network_types (type) VALUES ('ipv4');
400 -- Valid network configuration methods
401 CREATE TABLE network_methods (
402 method text PRIMARY KEY -- Configuration method
404 INSERT INTO network_methods (method) VALUES ('static');
405 INSERT INTO network_methods (method) VALUES ('dhcp');
406 INSERT INTO network_methods (method) VALUES ('proxy');
407 INSERT INTO network_methods (method) VALUES ('tap');
408 INSERT INTO network_methods (method) VALUES ('ipmi');
409 INSERT INTO network_methods (method) VALUES ('unknown');
411 -- Node network interfaces
412 CREATE TABLE nodenetworks (
414 nodenetwork_id serial PRIMARY KEY, -- Network interface identifier
415 node_id integer REFERENCES nodes NOT NULL, -- Which node
416 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
417 type text REFERENCES network_types NOT NULL, -- Addressing scheme
418 method text REFERENCES network_methods NOT NULL, -- Configuration method
420 -- Optional, depending on type and method
421 ip text, -- IP address
422 mac text, -- MAC address
423 gateway text, -- Default gateway address
424 network text, -- Network address
425 broadcast text, -- Network broadcast address
426 netmask text, -- Network mask
427 dns1 text, -- Primary DNS server
428 dns2 text, -- Secondary DNS server
429 bwlimit integer, -- Bandwidth limit in bps
430 hostname text -- Hostname of this interface
432 CREATE INDEX nodenetworks_node_id_idx ON nodenetworks (node_id);
434 -- Ordered by primary interface first
435 CREATE VIEW nodenetworks_ordered AS
436 SELECT node_id, nodenetwork_id
438 ORDER BY is_primary DESC;
440 -- Network interfaces on each node
441 CREATE VIEW node_nodenetworks AS
443 array_accum(nodenetwork_id) AS nodenetwork_ids
444 FROM nodenetworks_ordered
447 --------------------------------------------------------------------------------
448 -- Power control units (PCUs)
449 --------------------------------------------------------------------------------
453 pcu_id serial PRIMARY KEY, -- PCU identifier
454 site_id integer REFERENCES sites NOT NULL, -- Site identifier
455 hostname text, -- Hostname, not necessarily unique (multiple logical sites could use the same PCU)
456 ip text NOT NULL, -- IP, not necessarily unique
459 protocol text, -- Protocol, e.g. ssh or https or telnet
460 username text, -- Username, if applicable
461 "password" text, -- Password, if applicable
462 model text, -- Model, e.g. BayTech or iPal
463 notes text -- Random notes
465 CREATE INDEX pcus_site_id_idx ON pcus (site_id);
467 CREATE VIEW site_pcus AS
469 array_accum(pcu_id) AS pcu_ids
473 CREATE TABLE pcu_node (
474 pcu_id integer REFERENCES pcus NOT NULL, -- PCU identifier
475 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
476 port integer NOT NULL, -- Port number
477 PRIMARY KEY (pcu_id, node_id), -- The same node cannot be controlled by different ports
478 UNIQUE (pcu_id, port) -- The same port cannot control multiple nodes
480 CREATE INDEX pcu_node_pcu_id_idx ON pcu_node (pcu_id);
481 CREATE INDEX pcu_node_node_id_idx ON pcu_node (node_id);
483 CREATE VIEW node_pcus AS
485 array_accum(pcu_id) AS pcu_ids,
486 array_accum(port) AS ports
490 CREATE VIEW pcu_nodes AS
492 array_accum(node_id) AS node_ids,
493 array_accum(port) AS ports
497 --------------------------------------------------------------------------------
499 --------------------------------------------------------------------------------
501 CREATE TABLE slice_instantiations (
502 instantiation text PRIMARY KEY
504 INSERT INTO slice_instantiations (instantiation) VALUES ('not-instantiated'); -- Placeholder slice
505 INSERT INTO slice_instantiations (instantiation) VALUES ('plc-instantiated'); -- Instantiated by Node Manager
506 INSERT INTO slice_instantiations (instantiation) VALUES ('delegated'); -- Manually instantiated
509 CREATE TABLE slices (
510 slice_id serial PRIMARY KEY, -- Slice identifier
511 site_id integer REFERENCES sites NOT NULL, -- Site identifier
513 name text NOT NULL, -- Slice name
514 instantiation text REFERENCES slice_instantiations NOT NULL DEFAULT 'plc-instantiated', -- Slice state, e.g. plc-instantiated
515 url text, -- Project URL
516 description text, -- Project description
518 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
520 creator_person_id integer REFERENCES persons NOT NULL, -- Creator
521 created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation date
522 expires timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP + '2 weeks', -- Expiration date
524 is_deleted boolean NOT NULL DEFAULT false
526 CREATE INDEX slices_site_id_idx ON slices (site_id) WHERE is_deleted IS false;
527 CREATE INDEX slices_name_idx ON slices (name) WHERE is_deleted IS false;
530 CREATE TABLE slice_node (
531 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
532 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
533 PRIMARY KEY (slice_id, node_id)
535 CREATE INDEX slice_node_slice_id_idx ON slice_node (slice_id);
536 CREATE INDEX slice_node_node_id_idx ON slice_node (node_id);
538 -- Synonym for slice_node
539 CREATE VIEW slivers AS
540 SELECT * FROM slice_node;
542 -- Nodes in each slice
543 CREATE VIEW slice_nodes AS
545 array_accum(node_id) AS node_ids
549 -- Slices on each node
550 CREATE VIEW node_slices AS
552 array_accum(slice_id) AS slice_ids
556 -- Slices at each site
557 CREATE VIEW site_slices AS
559 array_accum(slice_id) AS slice_ids
561 WHERE is_deleted is false
565 CREATE TABLE slice_person (
566 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
567 person_id integer REFERENCES persons NOT NULL, -- Account identifier
568 PRIMARY KEY (slice_id, person_id)
570 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
571 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
573 -- Members of the slice
574 CREATE VIEW slice_persons AS
576 array_accum(person_id) AS person_ids
580 -- Slices of which each person is a member
581 CREATE VIEW person_slices AS
583 array_accum(slice_id) AS slice_ids
587 --------------------------------------------------------------------------------
589 --------------------------------------------------------------------------------
591 -- Slice attribute types
592 CREATE TABLE slice_attribute_types (
593 attribute_type_id serial PRIMARY KEY, -- Attribute type identifier
594 name text UNIQUE NOT NULL, -- Attribute name
595 description text, -- Attribute description
596 min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can set or change this attribute
599 -- Slice/sliver attributes
600 CREATE TABLE slice_attribute (
601 slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
602 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
603 node_id integer REFERENCES nodes, -- Sliver attribute if set
604 attribute_type_id integer REFERENCES slice_attribute_types NOT NULL, -- Attribute type identifier
607 CREATE INDEX slice_attribute_slice_id_idx ON slice_attribute (slice_id);
608 CREATE INDEX slice_attribute_node_id_idx ON slice_attribute (node_id);
610 CREATE VIEW slice_attributes AS
612 array_accum(slice_attribute_id) AS slice_attribute_ids
616 --------------------------------------------------------------------------------
618 --------------------------------------------------------------------------------
622 peer_id serial PRIMARY KEY, -- Peer identifier
623 peername text NOT NULL, -- Peer name
624 peer_url text NOT NULL, -- (HTTPS) URL of the peer PLCAPI interface
625 cacert text, -- (SSL) Public certificate of peer API server
626 key text, -- (GPG) Public key used for authentication
627 deleted boolean NOT NULL DEFAULT false
629 CREATE INDEX peers_peername_idx ON peers (peername) WHERE deleted IS false;
631 -- Objects at each peer
632 CREATE TABLE peer_site (
633 site_id integer REFERENCES sites PRIMARY KEY, -- Local site identifier
634 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
635 peer_site_id integer NOT NULL, -- Foreign site identifier at peer
636 UNIQUE (peer_id, peer_site_id) -- The same foreign site should not be cached twice
638 CREATE INDEX peer_site_peer_id_idx ON peers (peer_id);
640 CREATE VIEW peer_sites AS
642 array_accum(site_id) AS site_ids,
643 array_accum(peer_site_id) AS peer_site_ids
647 CREATE TABLE peer_person (
648 person_id integer REFERENCES persons PRIMARY KEY, -- Local user identifier
649 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
650 peer_person_id integer NOT NULL, -- Foreign user identifier at peer
651 UNIQUE (peer_id, peer_person_id) -- The same foreign user should not be cached twice
653 CREATE INDEX peer_person_peer_id_idx ON peer_person (peer_id);
655 CREATE VIEW peer_persons AS
657 array_accum(person_id) AS person_ids,
658 array_accum(peer_person_id) AS peer_person_ids
662 CREATE TABLE peer_key (
663 key_id integer REFERENCES keys PRIMARY KEY, -- Local key identifier
664 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
665 peer_key_id integer NOT NULL, -- Foreign key identifier at peer
666 UNIQUE (peer_id, peer_key_id) -- The same foreign key should not be cached twice
668 CREATE INDEX peer_key_peer_id_idx ON peer_key (peer_id);
670 CREATE VIEW peer_keys AS
672 array_accum(key_id) AS key_ids,
673 array_accum(peer_key_id) AS peer_key_ids
677 CREATE TABLE peer_node (
678 node_id integer REFERENCES nodes PRIMARY KEY, -- Local node identifier
679 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
680 peer_node_id integer NOT NULL, -- Foreign node identifier
681 UNIQUE (peer_id, peer_node_id) -- The same foreign node should not be cached twice
683 CREATE INDEX peer_node_peer_id_idx ON peer_node (peer_id);
685 CREATE VIEW peer_nodes AS
687 array_accum(node_id) AS node_ids,
688 array_accum(peer_node_id) AS peer_node_ids
692 CREATE TABLE peer_slice (
693 slice_id integer REFERENCES slices PRIMARY KEY, -- Local slice identifier
694 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
695 peer_slice_id integer NOT NULL, -- Slice identifier at peer
696 UNIQUE (peer_id, peer_slice_id) -- The same foreign slice should not be cached twice
698 CREATE INDEX peer_slice_peer_id_idx ON peer_slice (peer_id);
700 CREATE VIEW peer_slices AS
702 array_accum(slice_id) AS slice_ids,
703 array_accum(peer_slice_id) AS peer_slice_ids
707 --------------------------------------------------------------------------------
708 -- Authenticated sessions
709 --------------------------------------------------------------------------------
711 -- Authenticated sessions
712 CREATE TABLE sessions (
713 session_id text PRIMARY KEY, -- Session identifier
714 expires timestamp without time zone
717 -- People can have multiple sessions
718 CREATE TABLE person_session (
719 person_id integer REFERENCES persons NOT NULL, -- Account identifier
720 session_id text REFERENCES sessions NOT NULL, -- Session identifier
721 PRIMARY KEY (person_id, session_id),
722 UNIQUE (session_id) -- Sessions are unique
724 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
726 -- Nodes can have only one session
727 CREATE TABLE node_session (
728 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
729 session_id text REFERENCES sessions NOT NULL, -- Session identifier
730 UNIQUE (node_id), -- Nodes can have only one session
731 UNIQUE (session_id) -- Sessions are unique
734 --------------------------------------------------------------------------------
736 --------------------------------------------------------------------------------
738 CREATE TABLE messages (
739 message_id text PRIMARY KEY, -- Message name
740 subject text, -- Message summary
741 template text, -- Message template
742 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
745 --------------------------------------------------------------------------------
747 --------------------------------------------------------------------------------
750 CREATE TABLE events (
751 event_id serial PRIMARY KEY, -- Event identifier
752 person_id integer REFERENCES persons, -- Person responsible for event, if any
753 node_id integer REFERENCES nodes, -- Node responsible for event, if any
754 fault_code integer NOT NULL DEFAULT 0, -- Did this event result in error
755 call_name text NOT NULL, -- Call responsible for this event
756 call text NOT NULL, -- Call responsible for this event, including parameters
757 object_type text, -- What type of object is this event affecting
758 message text, -- High level description of this event
759 runtime float DEFAULT 0, -- Event run time
760 time timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP -- Event timestamp
763 -- Database object(s) that may have been affected by a particular event
764 CREATE TABLE event_object (
765 event_id integer REFERENCES events NOT NULL, -- Event identifier
766 object_id integer NOT NULL -- Object identifier
768 CREATE INDEX event_object_event_id_idx ON event_object (event_id);
769 CREATE INDEX event_object_object_id_idx ON event_object (object_id);
771 CREATE VIEW event_objects AS
773 array_accum(object_id) AS object_ids
777 --------------------------------------------------------------------------------
779 --------------------------------------------------------------------------------
781 CREATE OR REPLACE VIEW view_events AS
791 CAST(date_part('epoch', events.time) AS bigint) AS time,
792 COALESCE((SELECT object_ids FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_ids
795 CREATE OR REPLACE VIEW view_persons AS
804 persons.verification_key,
805 CAST(date_part('epoch', persons.verification_expires) AS bigint) AS verification_expires,
810 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
811 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
813 peer_person.peer_person_id,
814 COALESCE((SELECT role_ids FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS role_ids,
815 COALESCE((SELECT roles FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS roles,
816 COALESCE((SELECT site_ids FROM person_sites WHERE person_sites.person_id = persons.person_id), '{}') AS site_ids,
817 COALESCE((SELECT key_ids FROM person_keys WHERE person_keys.person_id = persons.person_id), '{}') AS key_ids,
818 COALESCE((SELECT slice_ids FROM person_slices WHERE person_slices.person_id = persons.person_id), '{}') AS slice_ids
820 LEFT JOIN peer_person USING (person_id);
822 CREATE OR REPLACE VIEW view_peers AS
825 COALESCE((SELECT site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS site_ids,
826 COALESCE((SELECT peer_site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS peer_site_ids,
827 COALESCE((SELECT person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS person_ids,
828 COALESCE((SELECT peer_person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS peer_person_ids,
829 COALESCE((SELECT key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS key_ids,
830 COALESCE((SELECT peer_key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS peer_key_ids,
831 COALESCE((SELECT node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS node_ids,
832 COALESCE((SELECT peer_node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS peer_node_ids,
833 COALESCE((SELECT slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS slice_ids,
834 COALESCE((SELECT peer_slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS peer_slice_ids
837 CREATE OR REPLACE VIEW view_nodes AS
849 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
850 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
852 peer_node.peer_node_id,
853 COALESCE((SELECT nodenetwork_ids FROM node_nodenetworks WHERE node_nodenetworks.node_id = nodes.node_id), '{}') AS nodenetwork_ids,
854 COALESCE((SELECT nodegroup_ids FROM node_nodegroups WHERE node_nodegroups.node_id = nodes.node_id), '{}') AS nodegroup_ids,
855 COALESCE((SELECT slice_ids FROM node_slices WHERE node_slices.node_id = nodes.node_id), '{}') AS slice_ids,
856 COALESCE((SELECT pcu_ids FROM node_pcus WHERE node_pcus.node_id = nodes.node_id), '{}') AS pcu_ids,
857 COALESCE((SELECT ports FROM node_pcus WHERE node_pcus.node_id = nodes.node_id), '{}') AS ports,
858 COALESCE((SELECT conf_file_ids FROM node_conf_files WHERE node_conf_files.node_id = nodes.node_id), '{}') AS conf_file_ids,
859 node_session.session_id AS session
861 LEFT JOIN peer_node USING (node_id)
862 LEFT JOIN node_session USING (node_id);
864 CREATE OR REPLACE VIEW view_nodegroups AS
867 COALESCE((SELECT node_ids FROM nodegroup_nodes WHERE nodegroup_nodes.nodegroup_id = nodegroups.nodegroup_id), '{}') AS node_ids,
868 COALESCE((SELECT conf_file_ids FROM nodegroup_conf_files WHERE nodegroup_conf_files.nodegroup_id = nodegroups.nodegroup_id), '{}') AS conf_file_ids
871 CREATE OR REPLACE VIEW view_conf_files AS
874 COALESCE((SELECT node_ids FROM conf_file_nodes WHERE conf_file_nodes.conf_file_id = conf_files.conf_file_id), '{}') AS node_ids,
875 COALESCE((SELECT nodegroup_ids FROM conf_file_nodegroups WHERE conf_file_nodegroups.conf_file_id = conf_files.conf_file_id), '{}') AS nodegroup_ids
878 CREATE OR REPLACE VIEW view_pcus AS
881 COALESCE((SELECT node_ids FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS node_ids,
882 COALESCE((SELECT ports FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS ports
885 CREATE OR REPLACE VIEW view_sites AS
890 sites.abbreviated_name,
899 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
900 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
902 peer_site.peer_site_id,
903 COALESCE((SELECT person_ids FROM site_persons WHERE site_persons.site_id = sites.site_id), '{}') AS person_ids,
904 COALESCE((SELECT node_ids FROM site_nodes WHERE site_nodes.site_id = sites.site_id), '{}') AS node_ids,
905 COALESCE((SELECT address_ids FROM site_addresses WHERE site_addresses.site_id = sites.site_id), '{}') AS address_ids,
906 COALESCE((SELECT slice_ids FROM site_slices WHERE site_slices.site_id = sites.site_id), '{}') AS slice_ids,
907 COALESCE((SELECT pcu_ids FROM site_pcus WHERE site_pcus.site_id = sites.site_id), '{}') AS pcu_ids
909 LEFT JOIN peer_site USING (site_id);
911 CREATE OR REPLACE VIEW view_addresses AS
914 COALESCE((SELECT address_type_ids FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_type_ids,
915 COALESCE((SELECT address_types FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_types
918 CREATE OR REPLACE VIEW view_keys AS
921 person_key.person_id,
925 LEFT JOIN person_key USING (key_id)
926 LEFT JOIN peer_key USING (key_id);
928 CREATE OR REPLACE VIEW view_slices AS
933 slices.instantiation,
937 slices.creator_person_id,
939 CAST(date_part('epoch', slices.created) AS bigint) AS created,
940 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
942 peer_slice.peer_slice_id,
943 COALESCE((SELECT node_ids FROM slice_nodes WHERE slice_nodes.slice_id = slices.slice_id), '{}') AS node_ids,
944 COALESCE((SELECT person_ids FROM slice_persons WHERE slice_persons.slice_id = slices.slice_id), '{}') AS person_ids,
945 COALESCE((SELECT slice_attribute_ids FROM slice_attributes WHERE slice_attributes.slice_id = slices.slice_id), '{}') AS slice_attribute_ids
947 LEFT JOIN peer_slice USING (slice_id);
949 CREATE OR REPLACE VIEW view_slice_attributes AS
951 slice_attribute.slice_attribute_id,
952 slice_attribute.slice_id,
953 slice_attribute.node_id,
954 slice_attribute_types.attribute_type_id,
955 slice_attribute_types.name,
956 slice_attribute_types.description,
957 slice_attribute_types.min_role_id,
958 slice_attribute.value
960 INNER JOIN slice_attribute_types USING (attribute_type_id);
962 CREATE OR REPLACE VIEW view_sessions AS
965 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
966 person_session.person_id,
969 LEFT JOIN person_session USING (session_id)
970 LEFT JOIN node_session USING (session_id);
972 --------------------------------------------------------------------------------
973 -- Built-in maintenance account and default site
974 --------------------------------------------------------------------------------
977 (first_name, last_name, email, password, enabled)
979 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
981 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
982 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
983 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
984 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
987 (login_base, name, abbreviated_name, max_slices)
989 ('pl', 'PlanetLab Central', 'PLC', 100);