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.60 2007/01/09 16:23:47 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 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
82 is_public boolean NOT NULL DEFAULT true, -- Shows up in public lists
83 max_slices integer NOT NULL DEFAULT 0, -- Maximum number of slices
84 max_slivers integer NOT NULL DEFAULT 1000, -- Maximum number of instantiated slivers
92 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
93 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
95 CREATE INDEX sites_login_base_idx ON sites (login_base) WHERE deleted IS false;
97 -- Account site membership
98 CREATE TABLE person_site (
99 person_id integer REFERENCES persons NOT NULL, -- Account identifier
100 site_id integer REFERENCES sites NOT NULL, -- Site identifier
101 is_primary boolean NOT NULL DEFAULT false, -- Is the primary site for this account
102 PRIMARY KEY (person_id, site_id)
104 CREATE INDEX person_site_person_id_idx ON person_site (person_id);
105 CREATE INDEX person_site_site_id_idx ON person_site (site_id);
107 -- Ordered by primary site first
108 CREATE VIEW person_site_ordered AS
109 SELECT person_id, site_id
111 ORDER BY is_primary DESC;
113 -- Sites that each person is a member of
114 CREATE VIEW person_sites AS
116 array_accum(site_id) AS site_ids
117 FROM person_site_ordered
120 -- Accounts at each site
121 CREATE VIEW site_persons AS
123 array_accum(person_id) AS person_ids
127 --------------------------------------------------------------------------------
129 --------------------------------------------------------------------------------
131 CREATE TABLE address_types (
132 address_type_id serial PRIMARY KEY, -- Address type identifier
133 name text UNIQUE NOT NULL, -- Address type
134 description text -- Address type description
137 INSERT INTO address_types (name) VALUES ('Personal');
138 INSERT INTO address_types (name) VALUES ('Shipping');
139 -- XXX Used to be Site
140 INSERT INTO address_types (name) VALUES ('Billing');
143 CREATE TABLE addresses (
144 address_id serial PRIMARY KEY, -- Address identifier
145 line1 text NOT NULL, -- Address line 1
146 line2 text, -- Address line 2
147 line3 text, -- Address line 3
148 city text NOT NULL, -- City
149 state text NOT NULL, -- State or province
150 postalcode text NOT NULL, -- Postal code
151 country text NOT NULL -- Country
154 -- Each mailing address can be one of several types
155 CREATE TABLE address_address_type (
156 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
157 address_type_id integer REFERENCES address_types NOT NULL, -- Address type
158 PRIMARY KEY (address_id, address_type_id)
160 CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
161 CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);
163 CREATE VIEW address_address_types AS
165 array_accum(address_type_id) AS address_type_ids,
166 array_accum(address_types.name) AS address_types
167 FROM address_address_type
168 LEFT JOIN address_types USING (address_type_id)
171 CREATE TABLE site_address (
172 site_id integer REFERENCES sites NOT NULL, -- Site identifier
173 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
174 PRIMARY KEY (site_id, address_id)
176 CREATE INDEX site_address_site_id_idx ON site_address (site_id);
177 CREATE INDEX site_address_address_id_idx ON site_address (address_id);
179 CREATE VIEW site_addresses AS
181 array_accum(address_id) AS address_ids
185 --------------------------------------------------------------------------------
186 -- Authentication Keys
187 --------------------------------------------------------------------------------
190 CREATE TABLE key_types (
191 key_type text PRIMARY KEY -- Key type
193 INSERT INTO key_types (key_type) VALUES ('ssh');
195 -- Authentication keys
197 key_id serial PRIMARY KEY, -- Key identifier
198 key_type text REFERENCES key_types NOT NULL, -- Key type
199 key text NOT NULL, -- Key material
200 is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
203 -- Account authentication key(s)
204 CREATE TABLE person_key (
205 key_id integer REFERENCES keys PRIMARY KEY, -- Key identifier
206 person_id integer REFERENCES persons NOT NULL -- Account identifier
208 CREATE INDEX person_key_person_id_idx ON person_key (person_id);
210 CREATE VIEW person_keys AS
212 array_accum(key_id) AS key_ids
216 --------------------------------------------------------------------------------
218 --------------------------------------------------------------------------------
220 -- Valid account roles
222 role_id integer PRIMARY KEY, -- Role identifier
223 name text UNIQUE NOT NULL -- Role symbolic name
225 INSERT INTO roles (role_id, name) VALUES (10, 'admin');
226 INSERT INTO roles (role_id, name) VALUES (20, 'pi');
227 INSERT INTO roles (role_id, name) VALUES (30, 'user');
228 INSERT INTO roles (role_id, name) VALUES (40, 'tech');
230 CREATE TABLE person_role (
231 person_id integer REFERENCES persons NOT NULL, -- Account identifier
232 role_id integer REFERENCES roles NOT NULL, -- Role identifier
233 PRIMARY KEY (person_id, role_id)
235 CREATE INDEX person_role_person_id_idx ON person_role (person_id);
238 CREATE VIEW person_roles AS
240 array_accum(role_id) AS role_ids,
241 array_accum(roles.name) AS roles
243 LEFT JOIN roles USING (role_id)
246 --------------------------------------------------------------------------------
248 --------------------------------------------------------------------------------
250 -- Valid node boot states
251 CREATE TABLE boot_states (
252 boot_state text PRIMARY KEY
254 INSERT INTO boot_states (boot_state) VALUES ('boot');
255 INSERT INTO boot_states (boot_state) VALUES ('dbg');
256 INSERT INTO boot_states (boot_state) VALUES ('inst');
257 INSERT INTO boot_states (boot_state) VALUES ('rins');
258 INSERT INTO boot_states (boot_state) VALUES ('rcnf');
259 INSERT INTO boot_states (boot_state) VALUES ('new');
264 node_id serial PRIMARY KEY, -- Node identifier
265 hostname text NOT NULL, -- Node hostname
266 site_id integer REFERENCES sites NOT NULL, -- At which site
268 boot_state text REFERENCES boot_states NOT NULL DEFAULT 'inst', -- Node boot state
269 deleted boolean NOT NULL DEFAULT false, -- Is deleted
272 model text, -- Hardware make and model
273 boot_nonce text, -- Random nonce updated by Boot Manager
274 version text, -- Boot CD version string updated by Boot Manager
275 ssh_rsa_key text, -- SSH host key updated by Boot Manager
276 key text, -- Node key generated by API when configuration file is downloaded
279 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
280 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
282 CREATE INDEX nodes_hostname_idx ON nodes (hostname) WHERE deleted IS false;
283 CREATE INDEX nodes_site_id_idx ON nodes (site_id) WHERE deleted IS false;
285 -- Nodes at each site
286 CREATE VIEW site_nodes AS
288 array_accum(node_id) AS node_ids
292 --------------------------------------------------------------------------------
294 --------------------------------------------------------------------------------
297 CREATE TABLE nodegroups (
298 nodegroup_id serial PRIMARY KEY, -- Group identifier
299 name text UNIQUE NOT NULL, -- Group name
300 description text -- Group description
303 -- Node group membership
304 CREATE TABLE nodegroup_node (
305 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Group identifier
306 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
307 PRIMARY KEY (nodegroup_id, node_id)
309 CREATE INDEX nodegroup_node_nodegroup_id_idx ON nodegroup_node (nodegroup_id);
310 CREATE INDEX nodegroup_node_node_id_idx ON nodegroup_node (node_id);
312 -- Nodes in each node group
313 CREATE VIEW nodegroup_nodes AS
315 array_accum(node_id) AS node_ids
317 GROUP BY nodegroup_id;
319 -- Node groups that each node is a member of
320 CREATE VIEW node_nodegroups AS
322 array_accum(nodegroup_id) AS nodegroup_ids
326 --------------------------------------------------------------------------------
327 -- Node configuration files
328 --------------------------------------------------------------------------------
330 CREATE TABLE conf_files (
331 conf_file_id serial PRIMARY KEY, -- Configuration file identifier
332 enabled bool NOT NULL DEFAULT true, -- Configuration file is active
333 source text NOT NULL, -- Relative path on the boot server where file can be downloaded
334 dest text NOT NULL, -- Absolute path where file should be installed
335 file_permissions text NOT NULL DEFAULT '0644', -- chmod(1) permissions
336 file_owner text NOT NULL DEFAULT 'root', -- chown(1) owner
337 file_group text NOT NULL DEFAULT 'root', -- chgrp(1) owner
338 preinstall_cmd text, -- Shell command to execute prior to installing
339 postinstall_cmd text, -- Shell command to execute after installing
340 error_cmd text, -- Shell command to execute if any error occurs
341 ignore_cmd_errors bool NOT NULL DEFAULT false, -- Install file anyway even if an error occurs
342 always_update bool NOT NULL DEFAULT false -- Always attempt to install file even if unchanged
345 CREATE TABLE conf_file_node (
346 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
347 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
348 PRIMARY KEY (conf_file_id, node_id)
350 CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
351 CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
353 -- Nodes linked to each configuration file
354 CREATE VIEW conf_file_nodes AS
356 array_accum(node_id) AS node_ids
358 GROUP BY conf_file_id;
360 -- Configuration files linked to each node
361 CREATE VIEW node_conf_files AS
363 array_accum(conf_file_id) AS conf_file_ids
367 CREATE TABLE conf_file_nodegroup (
368 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
369 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Node group identifier
370 PRIMARY KEY (conf_file_id, nodegroup_id)
372 CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
373 CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
375 -- Node groups linked to each configuration file
376 CREATE VIEW conf_file_nodegroups AS
378 array_accum(nodegroup_id) AS nodegroup_ids
379 FROM conf_file_nodegroup
380 GROUP BY conf_file_id;
382 -- Configuration files linked to each node group
383 CREATE VIEW nodegroup_conf_files AS
385 array_accum(conf_file_id) AS conf_file_ids
386 FROM conf_file_nodegroup
387 GROUP BY nodegroup_id;
389 --------------------------------------------------------------------------------
390 -- Node network interfaces
391 --------------------------------------------------------------------------------
393 -- Valid network addressing schemes
394 CREATE TABLE network_types (
395 type text PRIMARY KEY -- Addressing scheme
397 INSERT INTO network_types (type) VALUES ('ipv4');
399 -- Valid network configuration methods
400 CREATE TABLE network_methods (
401 method text PRIMARY KEY -- Configuration method
403 INSERT INTO network_methods (method) VALUES ('static');
404 INSERT INTO network_methods (method) VALUES ('dhcp');
405 INSERT INTO network_methods (method) VALUES ('proxy');
406 INSERT INTO network_methods (method) VALUES ('tap');
407 INSERT INTO network_methods (method) VALUES ('ipmi');
408 INSERT INTO network_methods (method) VALUES ('unknown');
410 -- Node network interfaces
411 CREATE TABLE nodenetworks (
413 nodenetwork_id serial PRIMARY KEY, -- Network interface identifier
414 node_id integer REFERENCES nodes NOT NULL, -- Which node
415 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
416 type text REFERENCES network_types NOT NULL, -- Addressing scheme
417 method text REFERENCES network_methods NOT NULL, -- Configuration method
419 -- Optional, depending on type and method
420 ip text, -- IP address
421 mac text, -- MAC address
422 gateway text, -- Default gateway address
423 network text, -- Network address
424 broadcast text, -- Network broadcast address
425 netmask text, -- Network mask
426 dns1 text, -- Primary DNS server
427 dns2 text, -- Secondary DNS server
428 bwlimit integer, -- Bandwidth limit in bps
429 hostname text -- Hostname of this interface
431 CREATE INDEX nodenetworks_node_id_idx ON nodenetworks (node_id);
433 -- Ordered by primary interface first
434 CREATE VIEW nodenetworks_ordered AS
435 SELECT node_id, nodenetwork_id
437 ORDER BY is_primary DESC;
439 -- Network interfaces on each node
440 CREATE VIEW node_nodenetworks AS
442 array_accum(nodenetwork_id) AS nodenetwork_ids
443 FROM nodenetworks_ordered
446 --------------------------------------------------------------------------------
447 -- Power control units (PCUs)
448 --------------------------------------------------------------------------------
452 pcu_id serial PRIMARY KEY, -- PCU identifier
453 site_id integer REFERENCES sites NOT NULL, -- Site identifier
454 hostname text, -- Hostname, not necessarily unique (multiple logical sites could use the same PCU)
455 ip text NOT NULL, -- IP, not necessarily unique
458 protocol text, -- Protocol, e.g. ssh or https or telnet
459 username text, -- Username, if applicable
460 "password" text, -- Password, if applicable
461 model text, -- Model, e.g. BayTech or iPal
462 notes text -- Random notes
464 CREATE INDEX pcus_site_id_idx ON pcus (site_id);
466 CREATE VIEW site_pcus AS
468 array_accum(pcu_id) AS pcu_ids
472 CREATE TABLE pcu_node (
473 pcu_id integer REFERENCES pcus NOT NULL, -- PCU identifier
474 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
475 port integer NOT NULL, -- Port number
476 PRIMARY KEY (pcu_id, node_id), -- The same node cannot be controlled by different ports
477 UNIQUE (pcu_id, port) -- The same port cannot control multiple nodes
479 CREATE INDEX pcu_node_pcu_id_idx ON pcu_node (pcu_id);
480 CREATE INDEX pcu_node_node_id_idx ON pcu_node (node_id);
482 CREATE VIEW node_pcus AS
484 array_accum(pcu_id) AS pcu_ids,
485 array_accum(port) AS ports
489 CREATE VIEW pcu_nodes AS
491 array_accum(node_id) AS node_ids,
492 array_accum(port) AS ports
496 --------------------------------------------------------------------------------
498 --------------------------------------------------------------------------------
500 CREATE TABLE slice_instantiations (
501 instantiation text PRIMARY KEY
503 INSERT INTO slice_instantiations (instantiation) VALUES ('not-instantiated'); -- Placeholder slice
504 INSERT INTO slice_instantiations (instantiation) VALUES ('plc-instantiated'); -- Instantiated by Node Manager
505 INSERT INTO slice_instantiations (instantiation) VALUES ('delegated'); -- Manually instantiated
508 CREATE TABLE slices (
509 slice_id serial PRIMARY KEY, -- Slice identifier
510 site_id integer REFERENCES sites NOT NULL, -- Site identifier
512 name text NOT NULL, -- Slice name
513 instantiation text REFERENCES slice_instantiations NOT NULL DEFAULT 'plc-instantiated', -- Slice state, e.g. plc-instantiated
514 url text, -- Project URL
515 description text, -- Project description
517 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
519 creator_person_id integer REFERENCES persons NOT NULL, -- Creator
520 created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation date
521 expires timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP + '2 weeks', -- Expiration date
523 is_deleted boolean NOT NULL DEFAULT false
525 CREATE INDEX slices_site_id_idx ON slices (site_id) WHERE is_deleted IS false;
526 CREATE INDEX slices_name_idx ON slices (name) WHERE is_deleted IS false;
529 CREATE TABLE slice_node (
530 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
531 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
532 PRIMARY KEY (slice_id, node_id)
534 CREATE INDEX slice_node_slice_id_idx ON slice_node (slice_id);
535 CREATE INDEX slice_node_node_id_idx ON slice_node (node_id);
537 -- Synonym for slice_node
538 CREATE VIEW slivers AS
539 SELECT * FROM slice_node;
541 -- Nodes in each slice
542 CREATE VIEW slice_nodes AS
544 array_accum(node_id) AS node_ids
548 -- Slices on each node
549 CREATE VIEW node_slices AS
551 array_accum(slice_id) AS slice_ids
555 -- Slices at each site
556 CREATE VIEW site_slices AS
558 array_accum(slice_id) AS slice_ids
560 WHERE is_deleted is false
564 CREATE TABLE slice_person (
565 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
566 person_id integer REFERENCES persons NOT NULL, -- Account identifier
567 PRIMARY KEY (slice_id, person_id)
569 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
570 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
572 -- Members of the slice
573 CREATE VIEW slice_persons AS
575 array_accum(person_id) AS person_ids
579 -- Slices of which each person is a member
580 CREATE VIEW person_slices AS
582 array_accum(slice_id) AS slice_ids
586 --------------------------------------------------------------------------------
588 --------------------------------------------------------------------------------
590 -- Slice attribute types
591 CREATE TABLE slice_attribute_types (
592 attribute_type_id serial PRIMARY KEY, -- Attribute type identifier
593 name text UNIQUE NOT NULL, -- Attribute name
594 description text, -- Attribute description
595 min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can set or change this attribute
598 -- Slice/sliver attributes
599 CREATE TABLE slice_attribute (
600 slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
601 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
602 node_id integer REFERENCES nodes, -- Sliver attribute if set
603 attribute_type_id integer REFERENCES slice_attribute_types NOT NULL, -- Attribute type identifier
606 CREATE INDEX slice_attribute_slice_id_idx ON slice_attribute (slice_id);
607 CREATE INDEX slice_attribute_node_id_idx ON slice_attribute (node_id);
609 CREATE VIEW slice_attributes AS
611 array_accum(slice_attribute_id) AS slice_attribute_ids
615 --------------------------------------------------------------------------------
617 --------------------------------------------------------------------------------
621 peer_id serial PRIMARY KEY, -- Peer identifier
622 peername text NOT NULL, -- Peer name
623 peer_url text NOT NULL, -- (HTTPS) URL of the peer PLCAPI interface
624 cacert text, -- (SSL) Public certificate of peer API server
625 key text, -- (GPG) Public key used for authentication
626 deleted boolean NOT NULL DEFAULT false
628 CREATE INDEX peers_peername_idx ON peers (peername) WHERE deleted IS false;
630 -- Objects at each peer
631 CREATE TABLE peer_site (
632 site_id integer REFERENCES sites PRIMARY KEY, -- Local site identifier
633 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
634 peer_site_id integer NOT NULL, -- Foreign site identifier at peer
635 UNIQUE (peer_id, peer_site_id) -- The same foreign site should not be cached twice
637 CREATE INDEX peer_site_peer_id_idx ON peers (peer_id);
639 CREATE VIEW peer_sites AS
641 array_accum(site_id) AS site_ids,
642 array_accum(peer_site_id) AS peer_site_ids
646 CREATE TABLE peer_person (
647 person_id integer REFERENCES persons PRIMARY KEY, -- Local user identifier
648 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
649 peer_person_id integer NOT NULL, -- Foreign user identifier at peer
650 UNIQUE (peer_id, peer_person_id) -- The same foreign user should not be cached twice
652 CREATE INDEX peer_person_peer_id_idx ON peer_person (peer_id);
654 CREATE VIEW peer_persons AS
656 array_accum(person_id) AS person_ids,
657 array_accum(peer_person_id) AS peer_person_ids
661 CREATE TABLE peer_key (
662 key_id integer REFERENCES keys PRIMARY KEY, -- Local key identifier
663 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
664 peer_key_id integer NOT NULL, -- Foreign key identifier at peer
665 UNIQUE (peer_id, peer_key_id) -- The same foreign key should not be cached twice
667 CREATE INDEX peer_key_peer_id_idx ON peer_key (peer_id);
669 CREATE VIEW peer_keys AS
671 array_accum(key_id) AS key_ids,
672 array_accum(peer_key_id) AS peer_key_ids
676 CREATE TABLE peer_node (
677 node_id integer REFERENCES nodes PRIMARY KEY, -- Local node identifier
678 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
679 peer_node_id integer NOT NULL, -- Foreign node identifier
680 UNIQUE (peer_id, peer_node_id) -- The same foreign node should not be cached twice
682 CREATE INDEX peer_node_peer_id_idx ON peer_node (peer_id);
684 CREATE VIEW peer_nodes AS
686 array_accum(node_id) AS node_ids,
687 array_accum(peer_node_id) AS peer_node_ids
691 CREATE TABLE peer_slice (
692 slice_id integer REFERENCES slices PRIMARY KEY, -- Local slice identifier
693 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
694 peer_slice_id integer NOT NULL, -- Slice identifier at peer
695 UNIQUE (peer_id, peer_slice_id) -- The same foreign slice should not be cached twice
697 CREATE INDEX peer_slice_peer_id_idx ON peer_slice (peer_id);
699 CREATE VIEW peer_slices AS
701 array_accum(slice_id) AS slice_ids,
702 array_accum(peer_slice_id) AS peer_slice_ids
706 --------------------------------------------------------------------------------
707 -- Authenticated sessions
708 --------------------------------------------------------------------------------
710 -- Authenticated sessions
711 CREATE TABLE sessions (
712 session_id text PRIMARY KEY, -- Session identifier
713 expires timestamp without time zone
716 -- People can have multiple sessions
717 CREATE TABLE person_session (
718 person_id integer REFERENCES persons NOT NULL, -- Account identifier
719 session_id text REFERENCES sessions NOT NULL, -- Session identifier
720 PRIMARY KEY (person_id, session_id),
721 UNIQUE (session_id) -- Sessions are unique
723 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
725 -- Nodes can have only one session
726 CREATE TABLE node_session (
727 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
728 session_id text REFERENCES sessions NOT NULL, -- Session identifier
729 UNIQUE (node_id), -- Nodes can have only one session
730 UNIQUE (session_id) -- Sessions are unique
733 --------------------------------------------------------------------------------
735 --------------------------------------------------------------------------------
737 CREATE TABLE messages (
738 message_id text PRIMARY KEY, -- Message name
739 subject text, -- Message summary
740 template text, -- Message template
741 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
744 --------------------------------------------------------------------------------
746 --------------------------------------------------------------------------------
749 CREATE TABLE events (
750 event_id serial PRIMARY KEY, -- Event identifier
751 person_id integer REFERENCES persons, -- Person responsible for event, if any
752 node_id integer REFERENCES nodes, -- Node responsible for event, if any
753 fault_code integer NOT NULL DEFAULT 0, -- Did this event result in error
754 call_name text NOT NULL, -- Call responsible for this event
755 call text NOT NULL, -- Call responsible for this event, including parameters
756 message text, -- High level description of this event
757 runtime float DEFAULT 0, -- Event run time
758 time timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP -- Event timestamp
761 -- Database object(s) that may have been affected by a particular event
762 CREATE TABLE event_object (
763 event_id integer REFERENCES events NOT NULL, -- Event identifier
764 object_id integer NOT NULL -- Object identifier
766 CREATE INDEX event_object_event_id_idx ON event_object (event_id);
767 CREATE INDEX event_object_object_id_idx ON event_object (object_id);
769 CREATE VIEW event_objects AS
771 array_accum(object_id) AS object_ids
775 --------------------------------------------------------------------------------
777 --------------------------------------------------------------------------------
779 CREATE VIEW view_events AS
789 CAST(date_part('epoch', events.time) AS bigint) AS time,
790 COALESCE(event_objects.object_ids, '{}') AS object_ids
792 LEFT JOIN event_objects USING (event_id);
794 CREATE VIEW view_persons AS
803 persons.verification_key,
804 persons.verification_expires,
809 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
810 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
812 peer_person.peer_person_id,
813 COALESCE(person_roles.role_ids, '{}') AS role_ids,
814 COALESCE(person_roles.roles, '{}') AS roles,
815 COALESCE(person_sites.site_ids, '{}') AS site_ids,
816 COALESCE(person_keys.key_ids, '{}') AS key_ids,
817 COALESCE(person_slices.slice_ids, '{}') AS slice_ids
819 LEFT JOIN peer_person USING (person_id)
820 LEFT JOIN person_roles USING (person_id)
821 LEFT JOIN person_sites USING (person_id)
822 LEFT JOIN person_keys USING (person_id)
823 LEFT JOIN person_slices USING (person_id);
825 CREATE VIEW view_peers AS
828 COALESCE(peer_sites.site_ids, '{}') AS site_ids,
829 COALESCE(peer_sites.peer_site_ids, '{}') AS peer_site_ids,
830 COALESCE(peer_persons.person_ids, '{}') AS person_ids,
831 COALESCE(peer_persons.peer_person_ids, '{}') AS peer_person_ids,
832 COALESCE(peer_keys.key_ids, '{}') AS key_ids,
833 COALESCE(peer_keys.peer_key_ids, '{}') AS peer_key_ids,
834 COALESCE(peer_nodes.node_ids, '{}') AS node_ids,
835 COALESCE(peer_nodes.peer_node_ids, '{}') AS peer_node_ids,
836 COALESCE(peer_slices.slice_ids, '{}') AS slice_ids,
837 COALESCE(peer_slices.peer_slice_ids, '{}') AS peer_slice_ids
839 LEFT JOIN peer_sites USING (peer_id)
840 LEFT JOIN peer_persons USING (peer_id)
841 LEFT JOIN peer_keys USING (peer_id)
842 LEFT JOIN peer_nodes USING (peer_id)
843 LEFT JOIN peer_slices USING (peer_id);
845 CREATE VIEW view_nodes AS
857 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
858 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
860 peer_node.peer_node_id,
861 COALESCE(node_nodenetworks.nodenetwork_ids, '{}') AS nodenetwork_ids,
862 COALESCE(node_nodegroups.nodegroup_ids, '{}') AS nodegroup_ids,
863 COALESCE(node_slices.slice_ids, '{}') AS slice_ids,
864 COALESCE(node_pcus.pcu_ids, '{}') AS pcu_ids,
865 COALESCE(node_pcus.ports, '{}') AS ports,
866 COALESCE(node_conf_files.conf_file_ids, '{}') AS conf_file_ids,
867 node_session.session_id AS session
869 LEFT JOIN peer_node USING (node_id)
870 LEFT JOIN node_nodenetworks USING (node_id)
871 LEFT JOIN node_nodegroups USING (node_id)
872 LEFT JOIN node_slices USING (node_id)
873 LEFT JOIN node_pcus USING (node_id)
874 LEFT JOIN node_conf_files USING (node_id)
875 LEFT JOIN node_session USING (node_id);
877 CREATE VIEW view_nodegroups AS
880 COALESCE(nodegroup_nodes.node_ids, '{}') AS node_ids,
881 COALESCE(nodegroup_conf_files.conf_file_ids, '{}') AS conf_file_ids
883 LEFT JOIN nodegroup_nodes USING (nodegroup_id)
884 LEFT JOIN nodegroup_conf_files USING (nodegroup_id);
886 CREATE VIEW view_conf_files AS
889 COALESCE(conf_file_nodes.node_ids, '{}') AS node_ids,
890 COALESCE(conf_file_nodegroups.nodegroup_ids, '{}') AS nodegroup_ids
892 LEFT JOIN conf_file_nodes USING (conf_file_id)
893 LEFT JOIN conf_file_nodegroups USING (conf_file_id);
895 CREATE VIEW view_pcus AS
898 COALESCE(pcu_nodes.node_ids, '{}') AS node_ids,
899 COALESCE(pcu_nodes.ports, '{}') AS ports
901 LEFT JOIN pcu_nodes USING (pcu_id);
903 CREATE VIEW view_sites AS
908 sites.abbreviated_name,
916 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
917 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
919 peer_site.peer_site_id,
920 COALESCE(site_persons.person_ids, '{}') AS person_ids,
921 COALESCE(site_nodes.node_ids, '{}') AS node_ids,
922 COALESCE(site_addresses.address_ids, '{}') AS address_ids,
923 COALESCE(site_slices.slice_ids, '{}') AS slice_ids,
924 COALESCE(site_pcus.pcu_ids, '{}') AS pcu_ids
926 LEFT JOIN peer_site USING (site_id)
927 LEFT JOIN site_persons USING (site_id)
928 LEFT JOIN site_nodes USING (site_id)
929 LEFT JOIN site_addresses USING (site_id)
930 LEFT JOIN site_slices USING (site_id)
931 LEFT JOIN site_pcus USING (site_id);
933 CREATE VIEW view_addresses AS
936 COALESCE(address_address_types.address_type_ids, '{}') AS address_type_ids,
937 COALESCE(address_address_types.address_types, '{}') AS address_types
939 LEFT JOIN address_address_types USING (address_id);
941 CREATE VIEW view_keys AS
944 person_key.person_id,
948 LEFT JOIN person_key USING (key_id)
949 LEFT JOIN peer_key USING (key_id);
951 CREATE VIEW view_slices AS
956 slices.instantiation,
960 slices.creator_person_id,
962 CAST(date_part('epoch', slices.created) AS bigint) AS created,
963 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
965 peer_slice.peer_slice_id,
966 COALESCE(slice_nodes.node_ids, '{}') AS node_ids,
967 COALESCE(slice_persons.person_ids, '{}') AS person_ids,
968 COALESCE(slice_attributes.slice_attribute_ids, '{}') AS slice_attribute_ids
970 LEFT JOIN peer_slice USING (slice_id)
971 LEFT JOIN slice_nodes USING (slice_id)
972 LEFT JOIN slice_persons USING (slice_id)
973 LEFT JOIN slice_attributes USING (slice_id);
975 CREATE VIEW view_slice_attributes AS
977 slice_attribute.slice_attribute_id,
978 slice_attribute.slice_id,
979 slice_attribute.node_id,
980 slice_attribute_types.attribute_type_id,
981 slice_attribute_types.name,
982 slice_attribute_types.description,
983 slice_attribute_types.min_role_id,
984 slice_attribute.value
986 INNER JOIN slice_attribute_types USING (attribute_type_id);
988 CREATE VIEW view_sessions AS
991 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
992 person_session.person_id,
995 LEFT JOIN person_session USING (session_id)
996 LEFT JOIN node_session USING (session_id);
998 --------------------------------------------------------------------------------
999 -- Built-in maintenance account and default site
1000 --------------------------------------------------------------------------------
1003 (first_name, last_name, email, password, enabled)
1005 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
1007 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
1008 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
1009 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
1010 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
1013 (login_base, name, abbreviated_name, max_slices)
1015 ('pl', 'PlanetLab Central', 'PLC', 100);