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
15 SET client_encoding = 'UNICODE';
17 --------------------------------------------------------------------------------
18 -- Aggregates and store procedures
19 --------------------------------------------------------------------------------
21 -- Like MySQL GROUP_CONCAT(), this function aggregates values into a
23 CREATE AGGREGATE array_accum (
25 basetype = anyelement,
30 --------------------------------------------------------------------------------
32 --------------------------------------------------------------------------------
35 CREATE TABLE plc_db_version (
36 version integer NOT NULL,
37 subversion integer NOT NULL DEFAULT 0
40 INSERT INTO plc_db_version (version, subversion) VALUES (4, 9);
42 --------------------------------------------------------------------------------
44 --------------------------------------------------------------------------------
47 CREATE TABLE persons (
49 person_id serial PRIMARY KEY, -- Account identifier
50 email text NOT NULL, -- E-mail address
51 first_name text NOT NULL, -- First name
52 last_name text NOT NULL, -- Last name
53 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
54 enabled boolean NOT NULL DEFAULT false, -- Has been disabled
57 password text NOT NULL DEFAULT 'nopass', -- Password (md5crypted)
58 verification_key text, -- Reset password key
59 verification_expires timestamp without time zone,
62 title text, -- Honorific
63 phone text, -- Telephone number
64 url text, -- Home page
65 bio text, -- Biography
68 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
69 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
71 CREATE INDEX persons_email_idx ON persons (email) WHERE deleted IS false;
73 --------------------------------------------------------------------------------
75 --------------------------------------------------------------------------------
80 site_id serial PRIMARY KEY, -- Site identifier
81 login_base text NOT NULL, -- Site slice prefix
82 name text NOT NULL, -- Site name
83 abbreviated_name text NOT NULL, -- Site abbreviated name
84 enabled boolean NOT NULL Default true, -- Is this site enabled
85 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
86 is_public boolean NOT NULL DEFAULT true, -- Shows up in public lists
87 max_slices integer NOT NULL DEFAULT 0, -- Maximum number of slices
88 max_slivers integer NOT NULL DEFAULT 1000, -- Maximum number of instantiated slivers
94 ext_consortium_id integer, -- external consortium id
97 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
98 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
100 CREATE INDEX sites_login_base_idx ON sites (login_base) WHERE deleted IS false;
102 -- Account site membership
103 CREATE TABLE person_site (
104 person_id integer REFERENCES persons NOT NULL, -- Account identifier
105 site_id integer REFERENCES sites NOT NULL, -- Site identifier
106 is_primary boolean NOT NULL DEFAULT false, -- Is the primary site for this account
107 PRIMARY KEY (person_id, site_id)
109 CREATE INDEX person_site_person_id_idx ON person_site (person_id);
110 CREATE INDEX person_site_site_id_idx ON person_site (site_id);
112 -- Ordered by primary site first
113 CREATE VIEW person_site_ordered AS
114 SELECT person_id, site_id
116 ORDER BY is_primary DESC;
118 -- Sites that each person is a member of
119 CREATE VIEW person_sites AS
121 array_accum(site_id) AS site_ids
122 FROM person_site_ordered
125 -- Accounts at each site
126 CREATE VIEW site_persons AS
128 array_accum(person_id) AS person_ids
132 --------------------------------------------------------------------------------
134 --------------------------------------------------------------------------------
136 CREATE TABLE address_types (
137 address_type_id serial PRIMARY KEY, -- Address type identifier
138 name text UNIQUE NOT NULL, -- Address type
139 description text -- Address type description
142 INSERT INTO address_types (name) VALUES ('Personal');
143 INSERT INTO address_types (name) VALUES ('Shipping');
144 -- XXX Used to be Site
145 INSERT INTO address_types (name) VALUES ('Billing');
148 CREATE TABLE addresses (
149 address_id serial PRIMARY KEY, -- Address identifier
150 line1 text NOT NULL, -- Address line 1
151 line2 text, -- Address line 2
152 line3 text, -- Address line 3
153 city text NOT NULL, -- City
154 state text NOT NULL, -- State or province
155 postalcode text NOT NULL, -- Postal code
156 country text NOT NULL -- Country
159 -- Each mailing address can be one of several types
160 CREATE TABLE address_address_type (
161 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
162 address_type_id integer REFERENCES address_types NOT NULL, -- Address type
163 PRIMARY KEY (address_id, address_type_id)
165 CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
166 CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);
168 CREATE VIEW address_address_types AS
170 array_accum(address_type_id) AS address_type_ids,
171 array_accum(address_types.name) AS address_types
172 FROM address_address_type
173 LEFT JOIN address_types USING (address_type_id)
176 CREATE TABLE site_address (
177 site_id integer REFERENCES sites NOT NULL, -- Site identifier
178 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
179 PRIMARY KEY (site_id, address_id)
181 CREATE INDEX site_address_site_id_idx ON site_address (site_id);
182 CREATE INDEX site_address_address_id_idx ON site_address (address_id);
184 CREATE VIEW site_addresses AS
186 array_accum(address_id) AS address_ids
190 --------------------------------------------------------------------------------
191 -- Authentication Keys
192 --------------------------------------------------------------------------------
195 CREATE TABLE key_types (
196 key_type text PRIMARY KEY -- Key type
198 INSERT INTO key_types (key_type) VALUES ('ssh');
200 -- Authentication keys
202 key_id serial PRIMARY KEY, -- Key identifier
203 key_type text REFERENCES key_types NOT NULL, -- Key type
204 key text NOT NULL, -- Key material
205 is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
208 -- Account authentication key(s)
209 CREATE TABLE person_key (
210 key_id integer REFERENCES keys PRIMARY KEY, -- Key identifier
211 person_id integer REFERENCES persons NOT NULL -- Account identifier
213 CREATE INDEX person_key_person_id_idx ON person_key (person_id);
215 CREATE VIEW person_keys AS
217 array_accum(key_id) AS key_ids
221 --------------------------------------------------------------------------------
223 --------------------------------------------------------------------------------
225 -- Valid account roles
227 role_id integer PRIMARY KEY, -- Role identifier
228 name text UNIQUE NOT NULL -- Role symbolic name
230 INSERT INTO roles (role_id, name) VALUES (10, 'admin');
231 INSERT INTO roles (role_id, name) VALUES (20, 'pi');
232 INSERT INTO roles (role_id, name) VALUES (30, 'user');
233 INSERT INTO roles (role_id, name) VALUES (40, 'tech');
235 CREATE TABLE person_role (
236 person_id integer REFERENCES persons NOT NULL, -- Account identifier
237 role_id integer REFERENCES roles NOT NULL, -- Role identifier
238 PRIMARY KEY (person_id, role_id)
240 CREATE INDEX person_role_person_id_idx ON person_role (person_id);
243 CREATE VIEW person_roles AS
245 array_accum(role_id) AS role_ids,
246 array_accum(roles.name) AS roles
248 LEFT JOIN roles USING (role_id)
251 --------------------------------------------------------------------------------
253 --------------------------------------------------------------------------------
255 -- Valid node boot states
256 CREATE TABLE boot_states (
257 boot_state text PRIMARY KEY
259 INSERT INTO boot_states (boot_state) VALUES ('boot');
260 INSERT INTO boot_states (boot_state) VALUES ('dbg');
261 INSERT INTO boot_states (boot_state) VALUES ('diag');
262 INSERT INTO boot_states (boot_state) VALUES ('disable');
263 INSERT INTO boot_states (boot_state) VALUES ('inst');
264 INSERT INTO boot_states (boot_state) VALUES ('rins');
265 INSERT INTO boot_states (boot_state) VALUES ('new');
270 node_id serial PRIMARY KEY, -- Node identifier
271 hostname text NOT NULL, -- Node hostname
272 site_id integer REFERENCES sites NOT NULL, -- At which site
274 boot_state text REFERENCES boot_states NOT NULL DEFAULT 'inst', -- Node boot state
275 deleted boolean NOT NULL DEFAULT false, -- Is deleted
278 model text, -- Hardware make and model
279 boot_nonce text, -- Random nonce updated by Boot Manager
280 version text, -- Boot CD version string updated by Boot Manager
281 ssh_rsa_key text, -- SSH host key updated by Boot Manager
282 key text, -- Node key generated by API when configuration file is downloaded
285 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
286 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
287 last_contact timestamp without time zone
289 CREATE INDEX nodes_hostname_idx ON nodes (hostname) WHERE deleted IS false;
290 CREATE INDEX nodes_site_id_idx ON nodes (site_id) WHERE deleted IS false;
292 -- Nodes at each site
293 CREATE VIEW site_nodes AS
295 array_accum(node_id) AS node_ids
297 WHERE deleted IS false
300 --------------------------------------------------------------------------------
302 --------------------------------------------------------------------------------
305 CREATE TABLE nodegroups (
306 nodegroup_id serial PRIMARY KEY, -- Group identifier
307 name text UNIQUE NOT NULL, -- Group name
308 description text -- Group description
311 -- Node group membership
312 CREATE TABLE nodegroup_node (
313 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Group identifier
314 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
315 PRIMARY KEY (nodegroup_id, node_id)
317 CREATE INDEX nodegroup_node_nodegroup_id_idx ON nodegroup_node (nodegroup_id);
318 CREATE INDEX nodegroup_node_node_id_idx ON nodegroup_node (node_id);
320 -- Nodes in each node group
321 CREATE VIEW nodegroup_nodes AS
323 array_accum(node_id) AS node_ids
325 GROUP BY nodegroup_id;
327 -- Node groups that each node is a member of
328 CREATE VIEW node_nodegroups AS
330 array_accum(nodegroup_id) AS nodegroup_ids
334 --------------------------------------------------------------------------------
335 -- Node configuration files
336 --------------------------------------------------------------------------------
338 CREATE TABLE conf_files (
339 conf_file_id serial PRIMARY KEY, -- Configuration file identifier
340 enabled bool NOT NULL DEFAULT true, -- Configuration file is active
341 source text NOT NULL, -- Relative path on the boot server where file can be downloaded
342 dest text NOT NULL, -- Absolute path where file should be installed
343 file_permissions text NOT NULL DEFAULT '0644', -- chmod(1) permissions
344 file_owner text NOT NULL DEFAULT 'root', -- chown(1) owner
345 file_group text NOT NULL DEFAULT 'root', -- chgrp(1) owner
346 preinstall_cmd text, -- Shell command to execute prior to installing
347 postinstall_cmd text, -- Shell command to execute after installing
348 error_cmd text, -- Shell command to execute if any error occurs
349 ignore_cmd_errors bool NOT NULL DEFAULT false, -- Install file anyway even if an error occurs
350 always_update bool NOT NULL DEFAULT false -- Always attempt to install file even if unchanged
353 CREATE TABLE conf_file_node (
354 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
355 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
356 PRIMARY KEY (conf_file_id, node_id)
358 CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
359 CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
361 -- Nodes linked to each configuration file
362 CREATE VIEW conf_file_nodes AS
364 array_accum(node_id) AS node_ids
366 GROUP BY conf_file_id;
368 -- Configuration files linked to each node
369 CREATE VIEW node_conf_files AS
371 array_accum(conf_file_id) AS conf_file_ids
375 CREATE TABLE conf_file_nodegroup (
376 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
377 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Node group identifier
378 PRIMARY KEY (conf_file_id, nodegroup_id)
380 CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
381 CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
383 -- Node groups linked to each configuration file
384 CREATE VIEW conf_file_nodegroups AS
386 array_accum(nodegroup_id) AS nodegroup_ids
387 FROM conf_file_nodegroup
388 GROUP BY conf_file_id;
390 -- Configuration files linked to each node group
391 CREATE VIEW nodegroup_conf_files AS
393 array_accum(conf_file_id) AS conf_file_ids
394 FROM conf_file_nodegroup
395 GROUP BY nodegroup_id;
397 --------------------------------------------------------------------------------
398 -- Node network interfaces
399 --------------------------------------------------------------------------------
401 -- Valid network addressing schemes
402 CREATE TABLE network_types (
403 type text PRIMARY KEY -- Addressing scheme
405 INSERT INTO network_types (type) VALUES ('ipv4');
407 -- Valid network configuration methods
408 CREATE TABLE network_methods (
409 method text PRIMARY KEY -- Configuration method
411 INSERT INTO network_methods (method) VALUES ('static');
412 INSERT INTO network_methods (method) VALUES ('dhcp');
413 INSERT INTO network_methods (method) VALUES ('proxy');
414 INSERT INTO network_methods (method) VALUES ('tap');
415 INSERT INTO network_methods (method) VALUES ('ipmi');
416 INSERT INTO network_methods (method) VALUES ('unknown');
418 -- Node network interfaces
419 CREATE TABLE nodenetworks (
421 nodenetwork_id serial PRIMARY KEY, -- Network interface identifier
422 node_id integer REFERENCES nodes NOT NULL, -- Which node
423 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
424 type text REFERENCES network_types NOT NULL, -- Addressing scheme
425 method text REFERENCES network_methods NOT NULL, -- Configuration method
427 -- Optional, depending on type and method
428 ip text, -- IP address
429 mac text, -- MAC address
430 gateway text, -- Default gateway address
431 network text, -- Network address
432 broadcast text, -- Network broadcast address
433 netmask text, -- Network mask
434 dns1 text, -- Primary DNS server
435 dns2 text, -- Secondary DNS server
436 bwlimit integer, -- Bandwidth limit in bps
437 hostname text -- Hostname of this interface
439 CREATE INDEX nodenetworks_node_id_idx ON nodenetworks (node_id);
441 -- Ordered by primary interface first
442 CREATE VIEW nodenetworks_ordered AS
443 SELECT node_id, nodenetwork_id
445 ORDER BY is_primary DESC;
447 -- Network interfaces on each node
448 CREATE VIEW node_nodenetworks AS
450 array_accum(nodenetwork_id) AS nodenetwork_ids
451 FROM nodenetworks_ordered
454 --------------------------------------------------------------------------------
455 -- Nodenetwork setting types and nodenetworks settings
456 --------------------------------------------------------------------------------
458 CREATE TABLE nodenetwork_setting_types (
459 nodenetwork_setting_type_id serial PRIMARY KEY,
460 -- Setting Type Identifier
461 name text UNIQUE NOT NULL, -- Setting Name
462 description text, -- Optional Description
463 category text NOT NULL, -- Category, e.g. Wifi, or whatever
464 min_role_id integer references roles -- If set, minimal role required
467 CREATE TABLE nodenetwork_setting (
468 nodenetwork_setting_id serial PRIMARY KEY, -- Nodenetwork Setting Identifier
469 nodenetwork_id integer REFERENCES nodenetworks NOT NULL,
470 -- the nodenetwork this applies to
471 nodenetwork_setting_type_id integer REFERENCES nodenetwork_setting_types NOT NULL,
476 CREATE OR REPLACE VIEW nodenetwork_settings AS
477 SELECT nodenetwork_id,
478 array_accum(nodenetwork_setting_id) AS nodenetwork_setting_ids
479 FROM nodenetwork_setting
480 GROUP BY nodenetwork_id;
482 CREATE OR REPLACE VIEW view_nodenetwork_settings AS
484 nodenetwork_setting.nodenetwork_setting_id,
485 nodenetwork_setting.nodenetwork_id,
486 nodenetwork_setting_types.nodenetwork_setting_type_id,
487 nodenetwork_setting_types.name,
488 nodenetwork_setting_types.description,
489 nodenetwork_setting_types.category,
490 nodenetwork_setting_types.min_role_id,
491 nodenetwork_setting.value
492 FROM nodenetwork_setting
493 INNER JOIN nodenetwork_setting_types USING (nodenetwork_setting_type_id);
495 CREATE OR REPLACE VIEW view_nodenetworks AS
497 nodenetworks.nodenetwork_id,
498 nodenetworks.node_id,
499 nodenetworks.is_primary,
504 nodenetworks.gateway,
505 nodenetworks.network,
506 nodenetworks.broadcast,
507 nodenetworks.netmask,
510 nodenetworks.bwlimit,
511 nodenetworks.hostname,
512 COALESCE((SELECT nodenetwork_setting_ids FROM nodenetwork_settings WHERE nodenetwork_settings.nodenetwork_id = nodenetworks.nodenetwork_id), '{}') AS nodenetwork_setting_ids
515 --------------------------------------------------------------------------------
516 -- Power control units (PCUs)
517 --------------------------------------------------------------------------------
521 pcu_id serial PRIMARY KEY, -- PCU identifier
522 site_id integer REFERENCES sites NOT NULL, -- Site identifier
523 hostname text, -- Hostname, not necessarily unique (multiple logical sites could use the same PCU)
524 ip text NOT NULL, -- IP, not necessarily unique
527 protocol text, -- Protocol, e.g. ssh or https or telnet
528 username text, -- Username, if applicable
529 "password" text, -- Password, if applicable
530 model text, -- Model, e.g. BayTech or iPal
531 notes text -- Random notes
533 CREATE INDEX pcus_site_id_idx ON pcus (site_id);
535 CREATE VIEW site_pcus AS
537 array_accum(pcu_id) AS pcu_ids
541 CREATE TABLE pcu_node (
542 pcu_id integer REFERENCES pcus NOT NULL, -- PCU identifier
543 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
544 port integer NOT NULL, -- Port number
545 PRIMARY KEY (pcu_id, node_id), -- The same node cannot be controlled by different ports
546 UNIQUE (pcu_id, port) -- The same port cannot control multiple nodes
548 CREATE INDEX pcu_node_pcu_id_idx ON pcu_node (pcu_id);
549 CREATE INDEX pcu_node_node_id_idx ON pcu_node (node_id);
551 CREATE VIEW node_pcus AS
553 array_accum(pcu_id) AS pcu_ids,
554 array_accum(port) AS ports
558 CREATE VIEW pcu_nodes AS
560 array_accum(node_id) AS node_ids,
561 array_accum(port) AS ports
565 --------------------------------------------------------------------------------
567 --------------------------------------------------------------------------------
569 CREATE TABLE slice_instantiations (
570 instantiation text PRIMARY KEY
572 INSERT INTO slice_instantiations (instantiation) VALUES ('not-instantiated'); -- Placeholder slice
573 INSERT INTO slice_instantiations (instantiation) VALUES ('plc-instantiated'); -- Instantiated by Node Manager
574 INSERT INTO slice_instantiations (instantiation) VALUES ('delegated'); -- Manually instantiated
575 INSERT INTO slice_instantiations (instantiation) VALUES ('nm-controller'); -- NM Controller
578 CREATE TABLE slices (
579 slice_id serial PRIMARY KEY, -- Slice identifier
580 site_id integer REFERENCES sites NOT NULL, -- Site identifier
582 name text NOT NULL, -- Slice name
583 instantiation text REFERENCES slice_instantiations NOT NULL DEFAULT 'plc-instantiated', -- Slice state, e.g. plc-instantiated
584 url text, -- Project URL
585 description text, -- Project description
587 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
589 creator_person_id integer REFERENCES persons, -- Creator
590 created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation date
591 expires timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP + '2 weeks', -- Expiration date
593 is_deleted boolean NOT NULL DEFAULT false
595 CREATE INDEX slices_site_id_idx ON slices (site_id) WHERE is_deleted IS false;
596 CREATE INDEX slices_name_idx ON slices (name) WHERE is_deleted IS false;
599 CREATE TABLE slice_node (
600 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
601 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
602 PRIMARY KEY (slice_id, node_id)
604 CREATE INDEX slice_node_slice_id_idx ON slice_node (slice_id);
605 CREATE INDEX slice_node_node_id_idx ON slice_node (node_id);
607 -- Synonym for slice_node
608 CREATE VIEW slivers AS
609 SELECT * FROM slice_node;
611 -- Nodes in each slice
612 CREATE VIEW slice_nodes AS
614 array_accum(node_id) AS node_ids
618 -- Slices on each node
619 CREATE VIEW node_slices AS
621 array_accum(slice_id) AS slice_ids
625 -- Slices at each site
626 CREATE VIEW site_slices AS
628 array_accum(slice_id) AS slice_ids
630 WHERE is_deleted is false
634 CREATE TABLE slice_person (
635 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
636 person_id integer REFERENCES persons NOT NULL, -- Account identifier
637 PRIMARY KEY (slice_id, person_id)
639 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
640 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
642 -- Members of the slice
643 CREATE VIEW slice_persons AS
645 array_accum(person_id) AS person_ids
649 -- Slices of which each person is a member
650 CREATE VIEW person_slices AS
652 array_accum(slice_id) AS slice_ids
656 --------------------------------------------------------------------------------
658 --------------------------------------------------------------------------------
659 -- slice whitelist on nodes
660 CREATE TABLE node_slice_whitelist (
661 node_id integer REFERENCES nodes NOT NULL, -- Node id of whitelist
662 slice_id integer REFERENCES slices NOT NULL, -- Slice id thats allowd on this node
663 PRIMARY KEY (node_id, slice_id)
665 CREATE INDEX node_slice_whitelist_node_id_idx ON node_slice_whitelist (node_id);
666 CREATE INDEX node_slice_whitelist_slice_id_idx ON node_slice_whitelist (slice_id);
668 -- Slices on each node
669 CREATE VIEW node_slices_whitelist AS
671 array_accum(slice_id) AS slice_ids_whitelist
672 FROM node_slice_whitelist
675 --------------------------------------------------------------------------------
677 --------------------------------------------------------------------------------
679 -- Slice attribute types
680 CREATE TABLE slice_attribute_types (
681 attribute_type_id serial PRIMARY KEY, -- Attribute type identifier
682 name text UNIQUE NOT NULL, -- Attribute name
683 description text, -- Attribute description
684 min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can set or change this attribute
687 -- Slice/sliver attributes
688 CREATE TABLE slice_attribute (
689 slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
690 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
691 node_id integer REFERENCES nodes, -- Sliver attribute if set
692 nodegroup_id integer REFERENCES nodegroups, -- Node group attribute if set
693 attribute_type_id integer REFERENCES slice_attribute_types NOT NULL, -- Attribute type identifier
696 CREATE INDEX slice_attribute_slice_id_idx ON slice_attribute (slice_id);
697 CREATE INDEX slice_attribute_node_id_idx ON slice_attribute (node_id);
698 CREATE INDEX slice_attribute_nodegroup_id_idx ON slice_attribute (nodegroup_id);
700 CREATE VIEW slice_attributes AS
702 array_accum(slice_attribute_id) AS slice_attribute_ids
706 --------------------------------------------------------------------------------
708 --------------------------------------------------------------------------------
711 CREATE TABLE initscripts (
712 initscript_id serial PRIMARY KEY, -- Initscript identifier
713 name text NOT NULL, -- Initscript name
714 enabled bool NOT NULL DEFAULT true, -- Initscript is active
715 script text NOT NULL, -- Initscript
718 CREATE INDEX initscripts_name_idx ON initscripts (name);
721 --------------------------------------------------------------------------------
723 --------------------------------------------------------------------------------
727 peer_id serial PRIMARY KEY, -- Peer identifier
728 peername text NOT NULL, -- Peer name
729 peer_url text NOT NULL, -- (HTTPS) URL of the peer PLCAPI interface
730 cacert text, -- (SSL) Public certificate of peer API server
731 key text, -- (GPG) Public key used for authentication
732 deleted boolean NOT NULL DEFAULT false
734 CREATE INDEX peers_peername_idx ON peers (peername) WHERE deleted IS false;
736 -- Objects at each peer
737 CREATE TABLE peer_site (
738 site_id integer REFERENCES sites PRIMARY KEY, -- Local site identifier
739 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
740 peer_site_id integer NOT NULL, -- Foreign site identifier at peer
741 UNIQUE (peer_id, peer_site_id) -- The same foreign site should not be cached twice
743 CREATE INDEX peer_site_peer_id_idx ON peers (peer_id);
745 CREATE VIEW peer_sites AS
747 array_accum(site_id) AS site_ids,
748 array_accum(peer_site_id) AS peer_site_ids
752 CREATE TABLE peer_person (
753 person_id integer REFERENCES persons PRIMARY KEY, -- Local user identifier
754 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
755 peer_person_id integer NOT NULL, -- Foreign user identifier at peer
756 UNIQUE (peer_id, peer_person_id) -- The same foreign user should not be cached twice
758 CREATE INDEX peer_person_peer_id_idx ON peer_person (peer_id);
760 CREATE VIEW peer_persons AS
762 array_accum(person_id) AS person_ids,
763 array_accum(peer_person_id) AS peer_person_ids
767 CREATE TABLE peer_key (
768 key_id integer REFERENCES keys PRIMARY KEY, -- Local key identifier
769 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
770 peer_key_id integer NOT NULL, -- Foreign key identifier at peer
771 UNIQUE (peer_id, peer_key_id) -- The same foreign key should not be cached twice
773 CREATE INDEX peer_key_peer_id_idx ON peer_key (peer_id);
775 CREATE VIEW peer_keys AS
777 array_accum(key_id) AS key_ids,
778 array_accum(peer_key_id) AS peer_key_ids
782 CREATE TABLE peer_node (
783 node_id integer REFERENCES nodes PRIMARY KEY, -- Local node identifier
784 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
785 peer_node_id integer NOT NULL, -- Foreign node identifier
786 UNIQUE (peer_id, peer_node_id) -- The same foreign node should not be cached twice
788 CREATE INDEX peer_node_peer_id_idx ON peer_node (peer_id);
790 CREATE VIEW peer_nodes AS
792 array_accum(node_id) AS node_ids,
793 array_accum(peer_node_id) AS peer_node_ids
797 CREATE TABLE peer_slice (
798 slice_id integer REFERENCES slices PRIMARY KEY, -- Local slice identifier
799 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
800 peer_slice_id integer NOT NULL, -- Slice identifier at peer
801 UNIQUE (peer_id, peer_slice_id) -- The same foreign slice should not be cached twice
803 CREATE INDEX peer_slice_peer_id_idx ON peer_slice (peer_id);
805 CREATE VIEW peer_slices AS
807 array_accum(slice_id) AS slice_ids,
808 array_accum(peer_slice_id) AS peer_slice_ids
812 --------------------------------------------------------------------------------
813 -- Authenticated sessions
814 --------------------------------------------------------------------------------
816 -- Authenticated sessions
817 CREATE TABLE sessions (
818 session_id text PRIMARY KEY, -- Session identifier
819 expires timestamp without time zone
822 -- People can have multiple sessions
823 CREATE TABLE person_session (
824 person_id integer REFERENCES persons NOT NULL, -- Account identifier
825 session_id text REFERENCES sessions NOT NULL, -- Session identifier
826 PRIMARY KEY (person_id, session_id),
827 UNIQUE (session_id) -- Sessions are unique
829 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
831 -- Nodes can have only one session
832 CREATE TABLE node_session (
833 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
834 session_id text REFERENCES sessions NOT NULL, -- Session identifier
835 UNIQUE (node_id), -- Nodes can have only one session
836 UNIQUE (session_id) -- Sessions are unique
841 -------------------------------------------------------------------------------
843 ------------------------------------------------------------------------------
844 CREATE TABLE pcu_types (
845 pcu_type_id serial PRIMARY KEY,
846 model text NOT NULL , -- PCU model name
847 name text -- Full PCU model name
849 CREATE INDEX pcu_types_model_idx ON pcu_types (model);
851 CREATE TABLE pcu_protocol_type (
852 pcu_protocol_type_id serial PRIMARY KEY,
853 pcu_type_id integer REFERENCES pcu_types NOT NULL, -- PCU type identifier
854 port integer NOT NULL, -- PCU port
855 protocol text NOT NULL, -- Protocol
856 supported boolean NOT NULL DEFAULT True -- Does PLC support
858 CREATE INDEX pcu_protocol_type_pcu_type_id ON pcu_protocol_type (pcu_type_id);
861 CREATE OR REPLACE VIEW pcu_protocol_types AS
863 array_accum(pcu_protocol_type_id) as pcu_protocol_type_ids
864 FROM pcu_protocol_type
865 GROUP BY pcu_type_id;
867 --------------------------------------------------------------------------------
869 --------------------------------------------------------------------------------
871 CREATE TABLE messages (
872 message_id text PRIMARY KEY, -- Message name
873 subject text, -- Message summary
874 template text, -- Message template
875 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
878 --------------------------------------------------------------------------------
880 --------------------------------------------------------------------------------
883 CREATE TABLE events (
884 event_id serial PRIMARY KEY, -- Event identifier
885 person_id integer REFERENCES persons, -- Person responsible for event, if any
886 node_id integer REFERENCES nodes, -- Node responsible for event, if any
887 auth_type text, -- Type of auth used. i.e. AuthMethod
888 fault_code integer NOT NULL DEFAULT 0, -- Did this event result in error
889 call_name text NOT NULL, -- Call responsible for this event
890 call text NOT NULL, -- Call responsible for this event, including parameters
891 message text, -- High level description of this event
892 runtime float DEFAULT 0, -- Event run time
893 time timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP -- Event timestamp
896 -- Database object(s) that may have been affected by a particular event
897 CREATE TABLE event_object (
898 event_id integer REFERENCES events NOT NULL, -- Event identifier
899 object_id integer NOT NULL, -- Object identifier
900 object_type text NOT NULL Default 'Unknown' -- What type of object is this event affecting
902 CREATE INDEX event_object_event_id_idx ON event_object (event_id);
903 CREATE INDEX event_object_object_id_idx ON event_object (object_id);
904 CREATE INDEX event_object_object_type_idx ON event_object (object_type);
906 CREATE OR REPLACE VIEW event_objects AS
908 array_accum(object_id) AS object_ids,
909 array_accum(object_type) AS object_types
913 --------------------------------------------------------------------------------
915 --------------------------------------------------------------------------------
916 CREATE OR REPLACE VIEW view_pcu_types AS
918 pcu_types.pcu_type_id,
921 COALESCE((SELECT pcu_protocol_type_ids FROM pcu_protocol_types WHERE pcu_protocol_types.pcu_type_id = pcu_types.pcu_type_id), '{}') AS pcu_protocol_type_ids
924 CREATE OR REPLACE VIEW view_events AS
935 CAST(date_part('epoch', events.time) AS bigint) AS time,
936 COALESCE((SELECT object_ids FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_ids,
937 COALESCE((SELECT object_types FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_types
940 CREATE OR REPLACE VIEW view_event_objects AS
950 CAST(date_part('epoch', events.time) AS bigint) AS time,
951 event_object.object_id,
952 event_object.object_type
953 FROM events LEFT JOIN event_object USING (event_id);
955 CREATE OR REPLACE VIEW view_persons AS
964 persons.verification_key,
965 CAST(date_part('epoch', persons.verification_expires) AS bigint) AS verification_expires,
970 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
971 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
973 peer_person.peer_person_id,
974 COALESCE((SELECT role_ids FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS role_ids,
975 COALESCE((SELECT roles FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS roles,
976 COALESCE((SELECT site_ids FROM person_sites WHERE person_sites.person_id = persons.person_id), '{}') AS site_ids,
977 COALESCE((SELECT key_ids FROM person_keys WHERE person_keys.person_id = persons.person_id), '{}') AS key_ids,
978 COALESCE((SELECT slice_ids FROM person_slices WHERE person_slices.person_id = persons.person_id), '{}') AS slice_ids
980 LEFT JOIN peer_person USING (person_id);
982 CREATE OR REPLACE VIEW view_peers AS
985 COALESCE((SELECT site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS site_ids,
986 COALESCE((SELECT peer_site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS peer_site_ids,
987 COALESCE((SELECT person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS person_ids,
988 COALESCE((SELECT peer_person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS peer_person_ids,
989 COALESCE((SELECT key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS key_ids,
990 COALESCE((SELECT peer_key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS peer_key_ids,
991 COALESCE((SELECT node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS node_ids,
992 COALESCE((SELECT peer_node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS peer_node_ids,
993 COALESCE((SELECT slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS slice_ids,
994 COALESCE((SELECT peer_slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS peer_slice_ids
997 CREATE OR REPLACE VIEW view_nodes AS
1009 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
1010 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
1011 CAST(date_part('epoch', nodes.last_contact) AS bigint) AS last_contact,
1013 peer_node.peer_node_id,
1014 COALESCE((SELECT nodenetwork_ids FROM node_nodenetworks WHERE node_nodenetworks.node_id = nodes.node_id), '{}') AS nodenetwork_ids,
1015 COALESCE((SELECT nodegroup_ids FROM node_nodegroups WHERE node_nodegroups.node_id = nodes.node_id), '{}') AS nodegroup_ids,
1016 COALESCE((SELECT slice_ids FROM node_slices WHERE node_slices.node_id = nodes.node_id), '{}') AS slice_ids,
1017 COALESCE((SELECT slice_ids_whitelist FROM node_slices_whitelist WHERE node_slices_whitelist.node_id = nodes.node_id), '{}') AS slice_ids_whitelist,
1018 COALESCE((SELECT pcu_ids FROM node_pcus WHERE node_pcus.node_id = nodes.node_id), '{}') AS pcu_ids,
1019 COALESCE((SELECT ports FROM node_pcus WHERE node_pcus.node_id = nodes.node_id), '{}') AS ports,
1020 COALESCE((SELECT conf_file_ids FROM node_conf_files WHERE node_conf_files.node_id = nodes.node_id), '{}') AS conf_file_ids,
1021 node_session.session_id AS session
1023 LEFT JOIN peer_node USING (node_id)
1024 LEFT JOIN node_session USING (node_id);
1026 CREATE OR REPLACE VIEW view_nodegroups AS
1029 COALESCE((SELECT node_ids FROM nodegroup_nodes WHERE nodegroup_nodes.nodegroup_id = nodegroups.nodegroup_id), '{}') AS node_ids,
1030 COALESCE((SELECT conf_file_ids FROM nodegroup_conf_files WHERE nodegroup_conf_files.nodegroup_id = nodegroups.nodegroup_id), '{}') AS conf_file_ids
1033 CREATE OR REPLACE VIEW view_conf_files AS
1036 COALESCE((SELECT node_ids FROM conf_file_nodes WHERE conf_file_nodes.conf_file_id = conf_files.conf_file_id), '{}') AS node_ids,
1037 COALESCE((SELECT nodegroup_ids FROM conf_file_nodegroups WHERE conf_file_nodegroups.conf_file_id = conf_files.conf_file_id), '{}') AS nodegroup_ids
1040 CREATE OR REPLACE VIEW view_pcus AS
1043 COALESCE((SELECT node_ids FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS node_ids,
1044 COALESCE((SELECT ports FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS ports
1047 CREATE OR REPLACE VIEW view_sites AS
1052 sites.abbreviated_name,
1061 sites.ext_consortium_id,
1062 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
1063 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
1065 peer_site.peer_site_id,
1066 COALESCE((SELECT person_ids FROM site_persons WHERE site_persons.site_id = sites.site_id), '{}') AS person_ids,
1067 COALESCE((SELECT node_ids FROM site_nodes WHERE site_nodes.site_id = sites.site_id), '{}') AS node_ids,
1068 COALESCE((SELECT address_ids FROM site_addresses WHERE site_addresses.site_id = sites.site_id), '{}') AS address_ids,
1069 COALESCE((SELECT slice_ids FROM site_slices WHERE site_slices.site_id = sites.site_id), '{}') AS slice_ids,
1070 COALESCE((SELECT pcu_ids FROM site_pcus WHERE site_pcus.site_id = sites.site_id), '{}') AS pcu_ids
1072 LEFT JOIN peer_site USING (site_id);
1074 CREATE OR REPLACE VIEW view_addresses AS
1077 COALESCE((SELECT address_type_ids FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_type_ids,
1078 COALESCE((SELECT address_types FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_types
1081 CREATE OR REPLACE VIEW view_keys AS
1084 person_key.person_id,
1086 peer_key.peer_key_id
1088 LEFT JOIN person_key USING (key_id)
1089 LEFT JOIN peer_key USING (key_id);
1091 CREATE OR REPLACE VIEW view_slices AS
1096 slices.instantiation,
1100 slices.creator_person_id,
1102 CAST(date_part('epoch', slices.created) AS bigint) AS created,
1103 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
1105 peer_slice.peer_slice_id,
1106 COALESCE((SELECT node_ids FROM slice_nodes WHERE slice_nodes.slice_id = slices.slice_id), '{}') AS node_ids,
1107 COALESCE((SELECT person_ids FROM slice_persons WHERE slice_persons.slice_id = slices.slice_id), '{}') AS person_ids,
1108 COALESCE((SELECT slice_attribute_ids FROM slice_attributes WHERE slice_attributes.slice_id = slices.slice_id), '{}') AS slice_attribute_ids
1110 LEFT JOIN peer_slice USING (slice_id);
1112 CREATE OR REPLACE VIEW view_slice_attributes AS
1114 slice_attribute.slice_attribute_id,
1115 slice_attribute.slice_id,
1116 slice_attribute.node_id,
1117 slice_attribute.nodegroup_id,
1118 slice_attribute_types.attribute_type_id,
1119 slice_attribute_types.name,
1120 slice_attribute_types.description,
1121 slice_attribute_types.min_role_id,
1122 slice_attribute.value
1123 FROM slice_attribute
1124 INNER JOIN slice_attribute_types USING (attribute_type_id);
1126 CREATE OR REPLACE VIEW view_sessions AS
1128 sessions.session_id,
1129 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
1130 person_session.person_id,
1131 node_session.node_id
1133 LEFT JOIN person_session USING (session_id)
1134 LEFT JOIN node_session USING (session_id);
1136 --------------------------------------------------------------------------------
1137 -- Built-in maintenance account and default site
1138 --------------------------------------------------------------------------------
1141 (first_name, last_name, email, password, enabled)
1143 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
1145 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
1146 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
1147 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
1148 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
1151 (login_base, name, abbreviated_name, max_slices)
1153 ('pl', 'PlanetLab Central', 'PLC', 100);