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.67 2007/01/29 20:48:27 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
35 -- subversion created on demand by plc.d/db
38 INSERT INTO plc_db_version (version) VALUES (4);
40 --------------------------------------------------------------------------------
42 --------------------------------------------------------------------------------
45 CREATE TABLE persons (
47 person_id serial PRIMARY KEY, -- Account identifier
48 email text NOT NULL, -- E-mail address
49 first_name text NOT NULL, -- First name
50 last_name text NOT NULL, -- Last name
51 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
52 enabled boolean NOT NULL DEFAULT false, -- Has been disabled
55 password text NOT NULL DEFAULT 'nopass', -- Password (md5crypted)
56 verification_key text, -- Reset password key
57 verification_expires timestamp without time zone,
60 title text, -- Honorific
61 phone text, -- Telephone number
62 url text, -- Home page
63 bio text, -- Biography
66 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
67 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
69 CREATE INDEX persons_email_idx ON persons (email) WHERE deleted IS false;
71 --------------------------------------------------------------------------------
73 --------------------------------------------------------------------------------
78 site_id serial PRIMARY KEY, -- Site identifier
79 login_base text NOT NULL, -- Site slice prefix
80 name text NOT NULL, -- Site name
81 abbreviated_name text NOT NULL, -- Site abbreviated name
82 enabled boolean NOT NULL Default true, -- Is this site enabled
83 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
84 is_public boolean NOT NULL DEFAULT true, -- Shows up in public lists
85 max_slices integer NOT NULL DEFAULT 0, -- Maximum number of slices
86 max_slivers integer NOT NULL DEFAULT 1000, -- Maximum number of instantiated slivers
94 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
95 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
97 CREATE INDEX sites_login_base_idx ON sites (login_base) WHERE deleted IS false;
99 -- Account site membership
100 CREATE TABLE person_site (
101 person_id integer REFERENCES persons NOT NULL, -- Account identifier
102 site_id integer REFERENCES sites NOT NULL, -- Site identifier
103 is_primary boolean NOT NULL DEFAULT false, -- Is the primary site for this account
104 PRIMARY KEY (person_id, site_id)
106 CREATE INDEX person_site_person_id_idx ON person_site (person_id);
107 CREATE INDEX person_site_site_id_idx ON person_site (site_id);
109 -- Ordered by primary site first
110 CREATE VIEW person_site_ordered AS
111 SELECT person_id, site_id
113 ORDER BY is_primary DESC;
115 -- Sites that each person is a member of
116 CREATE VIEW person_sites AS
118 array_accum(site_id) AS site_ids
119 FROM person_site_ordered
122 -- Accounts at each site
123 CREATE VIEW site_persons AS
125 array_accum(person_id) AS person_ids
129 --------------------------------------------------------------------------------
131 --------------------------------------------------------------------------------
133 CREATE TABLE address_types (
134 address_type_id serial PRIMARY KEY, -- Address type identifier
135 name text UNIQUE NOT NULL, -- Address type
136 description text -- Address type description
139 INSERT INTO address_types (name) VALUES ('Personal');
140 INSERT INTO address_types (name) VALUES ('Shipping');
141 -- XXX Used to be Site
142 INSERT INTO address_types (name) VALUES ('Billing');
145 CREATE TABLE addresses (
146 address_id serial PRIMARY KEY, -- Address identifier
147 line1 text NOT NULL, -- Address line 1
148 line2 text, -- Address line 2
149 line3 text, -- Address line 3
150 city text NOT NULL, -- City
151 state text NOT NULL, -- State or province
152 postalcode text NOT NULL, -- Postal code
153 country text NOT NULL -- Country
156 -- Each mailing address can be one of several types
157 CREATE TABLE address_address_type (
158 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
159 address_type_id integer REFERENCES address_types NOT NULL, -- Address type
160 PRIMARY KEY (address_id, address_type_id)
162 CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
163 CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);
165 CREATE VIEW address_address_types AS
167 array_accum(address_type_id) AS address_type_ids,
168 array_accum(address_types.name) AS address_types
169 FROM address_address_type
170 LEFT JOIN address_types USING (address_type_id)
173 CREATE TABLE site_address (
174 site_id integer REFERENCES sites NOT NULL, -- Site identifier
175 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
176 PRIMARY KEY (site_id, address_id)
178 CREATE INDEX site_address_site_id_idx ON site_address (site_id);
179 CREATE INDEX site_address_address_id_idx ON site_address (address_id);
181 CREATE VIEW site_addresses AS
183 array_accum(address_id) AS address_ids
187 --------------------------------------------------------------------------------
188 -- Authentication Keys
189 --------------------------------------------------------------------------------
192 CREATE TABLE key_types (
193 key_type text PRIMARY KEY -- Key type
195 INSERT INTO key_types (key_type) VALUES ('ssh');
197 -- Authentication keys
199 key_id serial PRIMARY KEY, -- Key identifier
200 key_type text REFERENCES key_types NOT NULL, -- Key type
201 key text NOT NULL, -- Key material
202 is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
205 -- Account authentication key(s)
206 CREATE TABLE person_key (
207 key_id integer REFERENCES keys PRIMARY KEY, -- Key identifier
208 person_id integer REFERENCES persons NOT NULL -- Account identifier
210 CREATE INDEX person_key_person_id_idx ON person_key (person_id);
212 CREATE VIEW person_keys AS
214 array_accum(key_id) AS key_ids
218 --------------------------------------------------------------------------------
220 --------------------------------------------------------------------------------
222 -- Valid account roles
224 role_id integer PRIMARY KEY, -- Role identifier
225 name text UNIQUE NOT NULL -- Role symbolic name
227 INSERT INTO roles (role_id, name) VALUES (10, 'admin');
228 INSERT INTO roles (role_id, name) VALUES (20, 'pi');
229 INSERT INTO roles (role_id, name) VALUES (30, 'user');
230 INSERT INTO roles (role_id, name) VALUES (40, 'tech');
232 CREATE TABLE person_role (
233 person_id integer REFERENCES persons NOT NULL, -- Account identifier
234 role_id integer REFERENCES roles NOT NULL, -- Role identifier
235 PRIMARY KEY (person_id, role_id)
237 CREATE INDEX person_role_person_id_idx ON person_role (person_id);
240 CREATE VIEW person_roles AS
242 array_accum(role_id) AS role_ids,
243 array_accum(roles.name) AS roles
245 LEFT JOIN roles USING (role_id)
248 --------------------------------------------------------------------------------
250 --------------------------------------------------------------------------------
252 -- Valid node boot states
253 CREATE TABLE boot_states (
254 boot_state text PRIMARY KEY
256 INSERT INTO boot_states (boot_state) VALUES ('boot');
257 INSERT INTO boot_states (boot_state) VALUES ('dbg');
258 INSERT INTO boot_states (boot_state) VALUES ('inst');
259 INSERT INTO boot_states (boot_state) VALUES ('rins');
260 INSERT INTO boot_states (boot_state) VALUES ('rcnf');
261 INSERT INTO boot_states (boot_state) VALUES ('new');
266 node_id serial PRIMARY KEY, -- Node identifier
267 hostname text NOT NULL, -- Node hostname
268 site_id integer REFERENCES sites NOT NULL, -- At which site
270 boot_state text REFERENCES boot_states NOT NULL DEFAULT 'inst', -- Node boot state
271 deleted boolean NOT NULL DEFAULT false, -- Is deleted
274 model text, -- Hardware make and model
275 boot_nonce text, -- Random nonce updated by Boot Manager
276 version text, -- Boot CD version string updated by Boot Manager
277 ssh_rsa_key text, -- SSH host key updated by Boot Manager
278 key text, -- Node key generated by API when configuration file is downloaded
281 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
282 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
284 CREATE INDEX nodes_hostname_idx ON nodes (hostname) WHERE deleted IS false;
285 CREATE INDEX nodes_site_id_idx ON nodes (site_id) WHERE deleted IS false;
287 -- Nodes at each site
288 CREATE VIEW site_nodes AS
290 array_accum(node_id) AS node_ids
294 --------------------------------------------------------------------------------
296 --------------------------------------------------------------------------------
299 CREATE TABLE nodegroups (
300 nodegroup_id serial PRIMARY KEY, -- Group identifier
301 name text UNIQUE NOT NULL, -- Group name
302 description text -- Group description
305 -- Node group membership
306 CREATE TABLE nodegroup_node (
307 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Group identifier
308 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
309 PRIMARY KEY (nodegroup_id, node_id)
311 CREATE INDEX nodegroup_node_nodegroup_id_idx ON nodegroup_node (nodegroup_id);
312 CREATE INDEX nodegroup_node_node_id_idx ON nodegroup_node (node_id);
314 -- Nodes in each node group
315 CREATE VIEW nodegroup_nodes AS
317 array_accum(node_id) AS node_ids
319 GROUP BY nodegroup_id;
321 -- Node groups that each node is a member of
322 CREATE VIEW node_nodegroups AS
324 array_accum(nodegroup_id) AS nodegroup_ids
328 --------------------------------------------------------------------------------
329 -- Node configuration files
330 --------------------------------------------------------------------------------
332 CREATE TABLE conf_files (
333 conf_file_id serial PRIMARY KEY, -- Configuration file identifier
334 enabled bool NOT NULL DEFAULT true, -- Configuration file is active
335 source text NOT NULL, -- Relative path on the boot server where file can be downloaded
336 dest text NOT NULL, -- Absolute path where file should be installed
337 file_permissions text NOT NULL DEFAULT '0644', -- chmod(1) permissions
338 file_owner text NOT NULL DEFAULT 'root', -- chown(1) owner
339 file_group text NOT NULL DEFAULT 'root', -- chgrp(1) owner
340 preinstall_cmd text, -- Shell command to execute prior to installing
341 postinstall_cmd text, -- Shell command to execute after installing
342 error_cmd text, -- Shell command to execute if any error occurs
343 ignore_cmd_errors bool NOT NULL DEFAULT false, -- Install file anyway even if an error occurs
344 always_update bool NOT NULL DEFAULT false -- Always attempt to install file even if unchanged
347 CREATE TABLE conf_file_node (
348 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
349 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
350 PRIMARY KEY (conf_file_id, node_id)
352 CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
353 CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
355 -- Nodes linked to each configuration file
356 CREATE VIEW conf_file_nodes AS
358 array_accum(node_id) AS node_ids
360 GROUP BY conf_file_id;
362 -- Configuration files linked to each node
363 CREATE VIEW node_conf_files AS
365 array_accum(conf_file_id) AS conf_file_ids
369 CREATE TABLE conf_file_nodegroup (
370 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
371 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Node group identifier
372 PRIMARY KEY (conf_file_id, nodegroup_id)
374 CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
375 CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
377 -- Node groups linked to each configuration file
378 CREATE VIEW conf_file_nodegroups AS
380 array_accum(nodegroup_id) AS nodegroup_ids
381 FROM conf_file_nodegroup
382 GROUP BY conf_file_id;
384 -- Configuration files linked to each node group
385 CREATE VIEW nodegroup_conf_files AS
387 array_accum(conf_file_id) AS conf_file_ids
388 FROM conf_file_nodegroup
389 GROUP BY nodegroup_id;
391 --------------------------------------------------------------------------------
392 -- Node network interfaces
393 --------------------------------------------------------------------------------
395 -- Valid network addressing schemes
396 CREATE TABLE network_types (
397 type text PRIMARY KEY -- Addressing scheme
399 INSERT INTO network_types (type) VALUES ('ipv4');
401 -- Valid network configuration methods
402 CREATE TABLE network_methods (
403 method text PRIMARY KEY -- Configuration method
405 INSERT INTO network_methods (method) VALUES ('static');
406 INSERT INTO network_methods (method) VALUES ('dhcp');
407 INSERT INTO network_methods (method) VALUES ('proxy');
408 INSERT INTO network_methods (method) VALUES ('tap');
409 INSERT INTO network_methods (method) VALUES ('ipmi');
410 INSERT INTO network_methods (method) VALUES ('unknown');
412 -- Node network interfaces
413 CREATE TABLE nodenetworks (
415 nodenetwork_id serial PRIMARY KEY, -- Network interface identifier
416 node_id integer REFERENCES nodes NOT NULL, -- Which node
417 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
418 type text REFERENCES network_types NOT NULL, -- Addressing scheme
419 method text REFERENCES network_methods NOT NULL, -- Configuration method
421 -- Optional, depending on type and method
422 ip text, -- IP address
423 mac text, -- MAC address
424 gateway text, -- Default gateway address
425 network text, -- Network address
426 broadcast text, -- Network broadcast address
427 netmask text, -- Network mask
428 dns1 text, -- Primary DNS server
429 dns2 text, -- Secondary DNS server
430 bwlimit integer, -- Bandwidth limit in bps
431 hostname text -- Hostname of this interface
433 CREATE INDEX nodenetworks_node_id_idx ON nodenetworks (node_id);
435 -- Ordered by primary interface first
436 CREATE VIEW nodenetworks_ordered AS
437 SELECT node_id, nodenetwork_id
439 ORDER BY is_primary DESC;
441 -- Network interfaces on each node
442 CREATE VIEW node_nodenetworks AS
444 array_accum(nodenetwork_id) AS nodenetwork_ids
445 FROM nodenetworks_ordered
448 --------------------------------------------------------------------------------
449 -- Power control units (PCUs)
450 --------------------------------------------------------------------------------
454 pcu_id serial PRIMARY KEY, -- PCU identifier
455 site_id integer REFERENCES sites NOT NULL, -- Site identifier
456 hostname text, -- Hostname, not necessarily unique (multiple logical sites could use the same PCU)
457 ip text NOT NULL, -- IP, not necessarily unique
460 protocol text, -- Protocol, e.g. ssh or https or telnet
461 username text, -- Username, if applicable
462 "password" text, -- Password, if applicable
463 model text, -- Model, e.g. BayTech or iPal
464 notes text -- Random notes
466 CREATE INDEX pcus_site_id_idx ON pcus (site_id);
468 CREATE VIEW site_pcus AS
470 array_accum(pcu_id) AS pcu_ids
474 CREATE TABLE pcu_node (
475 pcu_id integer REFERENCES pcus NOT NULL, -- PCU identifier
476 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
477 port integer NOT NULL, -- Port number
478 PRIMARY KEY (pcu_id, node_id), -- The same node cannot be controlled by different ports
479 UNIQUE (pcu_id, port) -- The same port cannot control multiple nodes
481 CREATE INDEX pcu_node_pcu_id_idx ON pcu_node (pcu_id);
482 CREATE INDEX pcu_node_node_id_idx ON pcu_node (node_id);
484 CREATE VIEW node_pcus AS
486 array_accum(pcu_id) AS pcu_ids,
487 array_accum(port) AS ports
491 CREATE VIEW pcu_nodes AS
493 array_accum(node_id) AS node_ids,
494 array_accum(port) AS ports
498 --------------------------------------------------------------------------------
500 --------------------------------------------------------------------------------
502 CREATE TABLE slice_instantiations (
503 instantiation text PRIMARY KEY
505 INSERT INTO slice_instantiations (instantiation) VALUES ('not-instantiated'); -- Placeholder slice
506 INSERT INTO slice_instantiations (instantiation) VALUES ('plc-instantiated'); -- Instantiated by Node Manager
507 INSERT INTO slice_instantiations (instantiation) VALUES ('delegated'); -- Manually instantiated
510 CREATE TABLE slices (
511 slice_id serial PRIMARY KEY, -- Slice identifier
512 site_id integer REFERENCES sites NOT NULL, -- Site identifier
514 name text NOT NULL, -- Slice name
515 instantiation text REFERENCES slice_instantiations NOT NULL DEFAULT 'plc-instantiated', -- Slice state, e.g. plc-instantiated
516 url text, -- Project URL
517 description text, -- Project description
519 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
521 creator_person_id integer REFERENCES persons NOT NULL, -- Creator
522 created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation date
523 expires timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP + '2 weeks', -- Expiration date
525 is_deleted boolean NOT NULL DEFAULT false
527 CREATE INDEX slices_site_id_idx ON slices (site_id) WHERE is_deleted IS false;
528 CREATE INDEX slices_name_idx ON slices (name) WHERE is_deleted IS false;
531 CREATE TABLE slice_node (
532 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
533 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
534 PRIMARY KEY (slice_id, node_id)
536 CREATE INDEX slice_node_slice_id_idx ON slice_node (slice_id);
537 CREATE INDEX slice_node_node_id_idx ON slice_node (node_id);
539 -- Synonym for slice_node
540 CREATE VIEW slivers AS
541 SELECT * FROM slice_node;
543 -- Nodes in each slice
544 CREATE VIEW slice_nodes AS
546 array_accum(node_id) AS node_ids
550 -- Slices on each node
551 CREATE VIEW node_slices AS
553 array_accum(slice_id) AS slice_ids
557 -- Slices at each site
558 CREATE VIEW site_slices AS
560 array_accum(slice_id) AS slice_ids
562 WHERE is_deleted is false
566 CREATE TABLE slice_person (
567 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
568 person_id integer REFERENCES persons NOT NULL, -- Account identifier
569 PRIMARY KEY (slice_id, person_id)
571 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
572 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
574 -- Members of the slice
575 CREATE VIEW slice_persons AS
577 array_accum(person_id) AS person_ids
581 -- Slices of which each person is a member
582 CREATE VIEW person_slices AS
584 array_accum(slice_id) AS slice_ids
588 --------------------------------------------------------------------------------
590 --------------------------------------------------------------------------------
592 -- Slice attribute types
593 CREATE TABLE slice_attribute_types (
594 attribute_type_id serial PRIMARY KEY, -- Attribute type identifier
595 name text UNIQUE NOT NULL, -- Attribute name
596 description text, -- Attribute description
597 min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can set or change this attribute
600 -- Slice/sliver attributes
601 CREATE TABLE slice_attribute (
602 slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
603 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
604 node_id integer REFERENCES nodes, -- Sliver attribute if set
605 attribute_type_id integer REFERENCES slice_attribute_types NOT NULL, -- Attribute type identifier
608 CREATE INDEX slice_attribute_slice_id_idx ON slice_attribute (slice_id);
609 CREATE INDEX slice_attribute_node_id_idx ON slice_attribute (node_id);
611 CREATE VIEW slice_attributes AS
613 array_accum(slice_attribute_id) AS slice_attribute_ids
617 --------------------------------------------------------------------------------
619 --------------------------------------------------------------------------------
623 peer_id serial PRIMARY KEY, -- Peer identifier
624 peername text NOT NULL, -- Peer name
625 peer_url text NOT NULL, -- (HTTPS) URL of the peer PLCAPI interface
626 cacert text, -- (SSL) Public certificate of peer API server
627 key text, -- (GPG) Public key used for authentication
628 deleted boolean NOT NULL DEFAULT false
630 CREATE INDEX peers_peername_idx ON peers (peername) WHERE deleted IS false;
632 -- Objects at each peer
633 CREATE TABLE peer_site (
634 site_id integer REFERENCES sites PRIMARY KEY, -- Local site identifier
635 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
636 peer_site_id integer NOT NULL, -- Foreign site identifier at peer
637 UNIQUE (peer_id, peer_site_id) -- The same foreign site should not be cached twice
639 CREATE INDEX peer_site_peer_id_idx ON peers (peer_id);
641 CREATE VIEW peer_sites AS
643 array_accum(site_id) AS site_ids,
644 array_accum(peer_site_id) AS peer_site_ids
648 CREATE TABLE peer_person (
649 person_id integer REFERENCES persons PRIMARY KEY, -- Local user identifier
650 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
651 peer_person_id integer NOT NULL, -- Foreign user identifier at peer
652 UNIQUE (peer_id, peer_person_id) -- The same foreign user should not be cached twice
654 CREATE INDEX peer_person_peer_id_idx ON peer_person (peer_id);
656 CREATE VIEW peer_persons AS
658 array_accum(person_id) AS person_ids,
659 array_accum(peer_person_id) AS peer_person_ids
663 CREATE TABLE peer_key (
664 key_id integer REFERENCES keys PRIMARY KEY, -- Local key identifier
665 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
666 peer_key_id integer NOT NULL, -- Foreign key identifier at peer
667 UNIQUE (peer_id, peer_key_id) -- The same foreign key should not be cached twice
669 CREATE INDEX peer_key_peer_id_idx ON peer_key (peer_id);
671 CREATE VIEW peer_keys AS
673 array_accum(key_id) AS key_ids,
674 array_accum(peer_key_id) AS peer_key_ids
678 CREATE TABLE peer_node (
679 node_id integer REFERENCES nodes PRIMARY KEY, -- Local node identifier
680 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
681 peer_node_id integer NOT NULL, -- Foreign node identifier
682 UNIQUE (peer_id, peer_node_id) -- The same foreign node should not be cached twice
684 CREATE INDEX peer_node_peer_id_idx ON peer_node (peer_id);
686 CREATE VIEW peer_nodes AS
688 array_accum(node_id) AS node_ids,
689 array_accum(peer_node_id) AS peer_node_ids
693 CREATE TABLE peer_slice (
694 slice_id integer REFERENCES slices PRIMARY KEY, -- Local slice identifier
695 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
696 peer_slice_id integer NOT NULL, -- Slice identifier at peer
697 UNIQUE (peer_id, peer_slice_id) -- The same foreign slice should not be cached twice
699 CREATE INDEX peer_slice_peer_id_idx ON peer_slice (peer_id);
701 CREATE VIEW peer_slices AS
703 array_accum(slice_id) AS slice_ids,
704 array_accum(peer_slice_id) AS peer_slice_ids
708 --------------------------------------------------------------------------------
709 -- Authenticated sessions
710 --------------------------------------------------------------------------------
712 -- Authenticated sessions
713 CREATE TABLE sessions (
714 session_id text PRIMARY KEY, -- Session identifier
715 expires timestamp without time zone
718 -- People can have multiple sessions
719 CREATE TABLE person_session (
720 person_id integer REFERENCES persons NOT NULL, -- Account identifier
721 session_id text REFERENCES sessions NOT NULL, -- Session identifier
722 PRIMARY KEY (person_id, session_id),
723 UNIQUE (session_id) -- Sessions are unique
725 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
727 -- Nodes can have only one session
728 CREATE TABLE node_session (
729 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
730 session_id text REFERENCES sessions NOT NULL, -- Session identifier
731 UNIQUE (node_id), -- Nodes can have only one session
732 UNIQUE (session_id) -- Sessions are unique
735 --------------------------------------------------------------------------------
737 --------------------------------------------------------------------------------
739 CREATE TABLE messages (
740 message_id text PRIMARY KEY, -- Message name
741 subject text, -- Message summary
742 template text, -- Message template
743 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
746 --------------------------------------------------------------------------------
748 --------------------------------------------------------------------------------
751 CREATE TABLE events (
752 event_id serial PRIMARY KEY, -- Event identifier
753 person_id integer REFERENCES persons, -- Person responsible for event, if any
754 node_id integer REFERENCES nodes, -- Node responsible for event, if any
755 fault_code integer NOT NULL DEFAULT 0, -- Did this event result in error
756 call_name text NOT NULL, -- Call responsible for this event
757 call text NOT NULL, -- Call responsible for this event, including parameters
758 object_type text, -- What type of object is this event affecting
759 message text, -- High level description of this event
760 runtime float DEFAULT 0, -- Event run time
761 time timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP -- Event timestamp
764 -- Database object(s) that may have been affected by a particular event
765 CREATE TABLE event_object (
766 event_id integer REFERENCES events NOT NULL, -- Event identifier
767 object_id integer NOT NULL -- Object identifier
769 CREATE INDEX event_object_event_id_idx ON event_object (event_id);
770 CREATE INDEX event_object_object_id_idx ON event_object (object_id);
772 CREATE VIEW event_objects AS
774 array_accum(object_id) AS object_ids
778 --------------------------------------------------------------------------------
780 --------------------------------------------------------------------------------
782 CREATE OR REPLACE VIEW view_events AS
792 CAST(date_part('epoch', events.time) AS bigint) AS time,
793 COALESCE((SELECT object_ids FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_ids
796 CREATE OR REPLACE VIEW view_persons AS
805 persons.verification_key,
806 CAST(date_part('epoch', persons.verification_expires) AS bigint) AS verification_expires,
811 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
812 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
814 peer_person.peer_person_id,
815 COALESCE((SELECT role_ids FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS role_ids,
816 COALESCE((SELECT roles FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS roles,
817 COALESCE((SELECT site_ids FROM person_sites WHERE person_sites.person_id = persons.person_id), '{}') AS site_ids,
818 COALESCE((SELECT key_ids FROM person_keys WHERE person_keys.person_id = persons.person_id), '{}') AS key_ids,
819 COALESCE((SELECT slice_ids FROM person_slices WHERE person_slices.person_id = persons.person_id), '{}') AS slice_ids
821 LEFT JOIN peer_person USING (person_id);
823 CREATE OR REPLACE VIEW view_peers AS
826 COALESCE((SELECT site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS site_ids,
827 COALESCE((SELECT peer_site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS peer_site_ids,
828 COALESCE((SELECT person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS person_ids,
829 COALESCE((SELECT peer_person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS peer_person_ids,
830 COALESCE((SELECT key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS key_ids,
831 COALESCE((SELECT peer_key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS peer_key_ids,
832 COALESCE((SELECT node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS node_ids,
833 COALESCE((SELECT peer_node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS peer_node_ids,
834 COALESCE((SELECT slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS slice_ids,
835 COALESCE((SELECT peer_slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS peer_slice_ids
838 CREATE OR REPLACE VIEW view_nodes AS
850 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
851 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
853 peer_node.peer_node_id,
854 COALESCE((SELECT nodenetwork_ids FROM node_nodenetworks WHERE node_nodenetworks.node_id = nodes.node_id), '{}') AS nodenetwork_ids,
855 COALESCE((SELECT nodegroup_ids FROM node_nodegroups WHERE node_nodegroups.node_id = nodes.node_id), '{}') AS nodegroup_ids,
856 COALESCE((SELECT slice_ids FROM node_slices WHERE node_slices.node_id = nodes.node_id), '{}') AS slice_ids,
857 COALESCE((SELECT pcu_ids FROM node_pcus WHERE node_pcus.node_id = nodes.node_id), '{}') AS pcu_ids,
858 COALESCE((SELECT ports FROM node_pcus WHERE node_pcus.node_id = nodes.node_id), '{}') AS ports,
859 COALESCE((SELECT conf_file_ids FROM node_conf_files WHERE node_conf_files.node_id = nodes.node_id), '{}') AS conf_file_ids,
860 node_session.session_id AS session
862 LEFT JOIN peer_node USING (node_id)
863 LEFT JOIN node_session USING (node_id);
865 CREATE OR REPLACE VIEW view_nodegroups AS
868 COALESCE((SELECT node_ids FROM nodegroup_nodes WHERE nodegroup_nodes.nodegroup_id = nodegroups.nodegroup_id), '{}') AS node_ids,
869 COALESCE((SELECT conf_file_ids FROM nodegroup_conf_files WHERE nodegroup_conf_files.nodegroup_id = nodegroups.nodegroup_id), '{}') AS conf_file_ids
872 CREATE OR REPLACE VIEW view_conf_files AS
875 COALESCE((SELECT node_ids FROM conf_file_nodes WHERE conf_file_nodes.conf_file_id = conf_files.conf_file_id), '{}') AS node_ids,
876 COALESCE((SELECT nodegroup_ids FROM conf_file_nodegroups WHERE conf_file_nodegroups.conf_file_id = conf_files.conf_file_id), '{}') AS nodegroup_ids
879 CREATE OR REPLACE VIEW view_pcus AS
882 COALESCE((SELECT node_ids FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS node_ids,
883 COALESCE((SELECT ports FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS ports
886 CREATE OR REPLACE VIEW view_sites AS
891 sites.abbreviated_name,
900 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
901 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
903 peer_site.peer_site_id,
904 COALESCE((SELECT person_ids FROM site_persons WHERE site_persons.site_id = sites.site_id), '{}') AS person_ids,
905 COALESCE((SELECT node_ids FROM site_nodes WHERE site_nodes.site_id = sites.site_id), '{}') AS node_ids,
906 COALESCE((SELECT address_ids FROM site_addresses WHERE site_addresses.site_id = sites.site_id), '{}') AS address_ids,
907 COALESCE((SELECT slice_ids FROM site_slices WHERE site_slices.site_id = sites.site_id), '{}') AS slice_ids,
908 COALESCE((SELECT pcu_ids FROM site_pcus WHERE site_pcus.site_id = sites.site_id), '{}') AS pcu_ids
910 LEFT JOIN peer_site USING (site_id);
912 CREATE OR REPLACE VIEW view_addresses AS
915 COALESCE((SELECT address_type_ids FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_type_ids,
916 COALESCE((SELECT address_types FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_types
919 CREATE OR REPLACE VIEW view_keys AS
922 person_key.person_id,
926 LEFT JOIN person_key USING (key_id)
927 LEFT JOIN peer_key USING (key_id);
929 CREATE OR REPLACE VIEW view_slices AS
934 slices.instantiation,
938 slices.creator_person_id,
940 CAST(date_part('epoch', slices.created) AS bigint) AS created,
941 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
943 peer_slice.peer_slice_id,
944 COALESCE((SELECT node_ids FROM slice_nodes WHERE slice_nodes.slice_id = slices.slice_id), '{}') AS node_ids,
945 COALESCE((SELECT person_ids FROM slice_persons WHERE slice_persons.slice_id = slices.slice_id), '{}') AS person_ids,
946 COALESCE((SELECT slice_attribute_ids FROM slice_attributes WHERE slice_attributes.slice_id = slices.slice_id), '{}') AS slice_attribute_ids
948 LEFT JOIN peer_slice USING (slice_id);
950 CREATE OR REPLACE VIEW view_slice_attributes AS
952 slice_attribute.slice_attribute_id,
953 slice_attribute.slice_id,
954 slice_attribute.node_id,
955 slice_attribute_types.attribute_type_id,
956 slice_attribute_types.name,
957 slice_attribute_types.description,
958 slice_attribute_types.min_role_id,
959 slice_attribute.value
961 INNER JOIN slice_attribute_types USING (attribute_type_id);
963 CREATE OR REPLACE VIEW view_sessions AS
966 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
967 person_session.person_id,
970 LEFT JOIN person_session USING (session_id)
971 LEFT JOIN node_session USING (session_id);
973 --------------------------------------------------------------------------------
974 -- Built-in maintenance account and default site
975 --------------------------------------------------------------------------------
978 (first_name, last_name, email, password, enabled)
980 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
982 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
983 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
984 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
985 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
988 (login_base, name, abbreviated_name, max_slices)
990 ('pl', 'PlanetLab Central', 'PLC', 100);