2 -- PlanetLab Central database schema
3 -- Version 5, 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>
9 -- Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
11 -- Copyright (C) 2006 The Trustees of Princeton University
16 SET client_encoding = 'UNICODE';
18 --------------------------------------------------------------------------------
20 --------------------------------------------------------------------------------
23 CREATE TABLE plc_db_version (
24 version integer NOT NULL,
25 subversion integer NOT NULL DEFAULT 0
28 INSERT INTO plc_db_version (version, subversion) VALUES (5, 0);
30 --------------------------------------------------------------------------------
31 -- Aggregates and store procedures
32 --------------------------------------------------------------------------------
34 -- Like MySQL GROUP_CONCAT(), this function aggregates values into a
36 CREATE AGGREGATE array_accum (
38 basetype = anyelement,
43 --------------------------------------------------------------------------------
45 --------------------------------------------------------------------------------
48 CREATE TABLE persons (
50 person_id serial PRIMARY KEY, -- Account identifier
51 email text NOT NULL, -- E-mail address
52 first_name text NOT NULL, -- First name
53 last_name text NOT NULL, -- Last name
54 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
55 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);
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);
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 OR REPLACE 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 OR REPLACE VIEW person_sites AS
121 array_accum(site_id) AS site_ids
122 FROM person_site_ordered
125 -- Accounts at each site
126 CREATE OR REPLACE 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 -- 'Billing' Used to be 'Site'
143 INSERT INTO address_types (name) VALUES ('Personal'), ('Shipping'), ('Billing');
146 CREATE TABLE addresses (
147 address_id serial PRIMARY KEY, -- Address identifier
148 line1 text NOT NULL, -- Address line 1
149 line2 text, -- Address line 2
150 line3 text, -- Address line 3
151 city text NOT NULL, -- City
152 state text NOT NULL, -- State or province
153 postalcode text NOT NULL, -- Postal code
154 country text NOT NULL -- Country
157 -- Each mailing address can be one of several types
158 CREATE TABLE address_address_type (
159 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
160 address_type_id integer REFERENCES address_types NOT NULL, -- Address type
161 PRIMARY KEY (address_id, address_type_id)
163 CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
164 CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);
166 CREATE OR REPLACE VIEW address_address_types AS
168 array_accum(address_type_id) AS address_type_ids,
169 array_accum(address_types.name) AS address_types
170 FROM address_address_type
171 LEFT JOIN address_types USING (address_type_id)
174 CREATE TABLE site_address (
175 site_id integer REFERENCES sites NOT NULL, -- Site identifier
176 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
177 PRIMARY KEY (site_id, address_id)
179 CREATE INDEX site_address_site_id_idx ON site_address (site_id);
180 CREATE INDEX site_address_address_id_idx ON site_address (address_id);
182 CREATE OR REPLACE VIEW site_addresses AS
184 array_accum(address_id) AS address_ids
188 --------------------------------------------------------------------------------
189 -- Authentication Keys
190 --------------------------------------------------------------------------------
193 CREATE TABLE key_types (
194 key_type text PRIMARY KEY -- Key type
196 INSERT INTO key_types (key_type) VALUES ('ssh');
198 -- Authentication keys
200 key_id serial PRIMARY KEY, -- Key identifier
201 key_type text REFERENCES key_types NOT NULL, -- Key type
202 key text NOT NULL, -- Key material
203 is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
206 -- Account authentication key(s)
207 CREATE TABLE person_key (
208 key_id integer REFERENCES keys PRIMARY KEY, -- Key identifier
209 person_id integer REFERENCES persons NOT NULL -- Account identifier
211 CREATE INDEX person_key_person_id_idx ON person_key (person_id);
213 CREATE OR REPLACE VIEW person_keys AS
215 array_accum(key_id) AS key_ids
219 --------------------------------------------------------------------------------
221 --------------------------------------------------------------------------------
223 -- Valid account roles
225 role_id integer PRIMARY KEY, -- Role identifier
226 name text UNIQUE NOT NULL -- Role symbolic name
228 INSERT INTO roles (role_id, name) VALUES (10, 'admin'), (20, 'pi'), (30, 'user'), (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 OR REPLACE 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)
255 VALUES ('boot'), ('dbg'), ('diag'), ('disable'), ('inst'), ('rins'), ('new');
260 node_id serial PRIMARY KEY, -- Node identifier
261 hostname text NOT NULL, -- Node hostname
262 site_id integer REFERENCES sites NOT NULL, -- At which site
264 boot_state text REFERENCES boot_states NOT NULL -- Node boot state
266 deleted boolean NOT NULL DEFAULT false, -- Is deleted
269 model text, -- Hardware make and model
270 boot_nonce text, -- Random nonce updated by Boot Manager
271 version text, -- Boot CD version string updated by Boot Manager
272 ssh_rsa_key text, -- SSH host key updated by Boot Manager
273 key text, -- Node key generated when boot file is downloaded
276 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
277 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
278 last_contact timestamp without time zone
280 CREATE INDEX nodes_hostname_idx ON nodes (hostname);
281 CREATE INDEX nodes_site_id_idx ON nodes (site_id);
283 -- Nodes at each site
284 CREATE OR REPLACE VIEW site_nodes AS
286 array_accum(node_id) AS node_ids
288 WHERE deleted IS false
291 --------------------------------------------------------------------------------
293 --------------------------------------------------------------------------------
294 CREATE TABLE tag_types (
296 tag_type_id serial PRIMARY KEY, -- ID
297 tagname text UNIQUE NOT NULL, -- Tag Name
298 description text, -- Optional Description
299 min_role_id integer REFERENCES roles DEFAULT 10, -- set minimal role required
300 category text NOT NULL DEFAULT 'general' -- Free text for grouping tags together
303 CREATE TABLE node_tag (
304 node_tag_id serial PRIMARY KEY, -- ID
305 node_id integer REFERENCES nodes NOT NULL, -- node id
306 tag_type_id integer REFERENCES tag_types, -- tag type id
307 tagvalue text -- value attached
310 CREATE OR REPLACE VIEW node_tags AS
312 array_accum(node_tag_id) AS tag_ids
316 CREATE OR REPLACE VIEW view_node_tags AS
318 node_tag.node_tag_id,
321 tag_types.tag_type_id,
323 tag_types.description,
325 tag_types.min_role_id,
328 INNER JOIN tag_types USING (tag_type_id)
329 INNER JOIN nodes USING (node_id);
331 --------------------------------------------------------------------------------
332 -- (network) interfaces
333 --------------------------------------------------------------------------------
335 -- Valid network addressing schemes
336 CREATE TABLE network_types (
337 type text PRIMARY KEY -- Addressing scheme
339 INSERT INTO network_types (type) VALUES ('ipv4');
341 -- Valid network configuration methods
342 CREATE TABLE network_methods (
343 method text PRIMARY KEY -- Configuration method
345 INSERT INTO network_methods (method) VALUES
346 ('static'), ('dhcp'), ('proxy'), ('tap'), ('ipmi'), ('unknown');
348 -- Node network interfaces
349 CREATE TABLE interfaces (
351 interface_id serial PRIMARY KEY, -- Network interface identifier
352 node_id integer REFERENCES nodes NOT NULL, -- Which node
353 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
354 type text REFERENCES network_types NOT NULL, -- Addressing scheme
355 method text REFERENCES network_methods NOT NULL, -- Configuration method
357 -- Optional, depending on type and method
358 ip text, -- IP address
359 mac text, -- MAC address
360 gateway text, -- Default gateway address
361 network text, -- Network address
362 broadcast text, -- Network broadcast address
363 netmask text, -- Network mask
364 dns1 text, -- Primary DNS server
365 dns2 text, -- Secondary DNS server
366 bwlimit integer, -- Bandwidth limit in bps
367 hostname text -- Hostname of this interface
369 CREATE INDEX interfaces_node_id_idx ON interfaces (node_id);
371 -- Ordered by primary interface first
372 CREATE OR REPLACE VIEW interfaces_ordered AS
373 SELECT node_id, interface_id
375 ORDER BY is_primary DESC;
377 -- Network interfaces on each node
378 CREATE OR REPLACE VIEW node_interfaces AS
380 array_accum(interface_id) AS interface_ids
381 FROM interfaces_ordered
384 --------------------------------------------------------------------------------
385 -- Interface settings
386 --------------------------------------------------------------------------------
388 CREATE TABLE interface_setting (
389 interface_setting_id serial PRIMARY KEY, -- Interface Setting Identifier
390 interface_id integer REFERENCES interfaces NOT NULL,-- the interface this applies to
391 tag_type_id integer REFERENCES tag_types NOT NULL, -- the setting type
392 value text -- value attached
395 CREATE OR REPLACE VIEW interface_settings AS
397 array_accum(interface_setting_id) AS interface_setting_ids
398 FROM interface_setting
399 GROUP BY interface_id;
401 CREATE OR REPLACE VIEW view_interface_settings AS
403 interface_setting.interface_setting_id,
404 interface_setting.interface_id,
405 tag_types.tag_type_id,
407 tag_types.description,
409 tag_types.min_role_id,
410 interface_setting.value
411 FROM interface_setting
412 INNER JOIN tag_types USING (tag_type_id);
414 CREATE OR REPLACE VIEW view_interfaces AS
416 interfaces.interface_id,
418 interfaces.is_primary,
425 interfaces.broadcast,
431 COALESCE((SELECT interface_setting_ids FROM interface_settings WHERE interface_settings.interface_id = interfaces.interface_id), '{}') AS interface_setting_ids
434 --------------------------------------------------------------------------------
435 -- ilinks : links between interfaces
436 --------------------------------------------------------------------------------
438 ilink_id serial PRIMARY KEY, -- id
439 tag_type_id integer REFERENCES tag_types, -- id of the tag type
440 src_interface_id integer REFERENCES interfaces not NULL, -- id of src interface
441 dst_interface_id integer REFERENCES interfaces NOT NULL, -- id of dst interface
442 value text -- optional value on the link
445 CREATE OR REPLACE VIEW view_ilinks AS
446 SELECT * FROM tag_types
447 INNER JOIN ilink USING (tag_type_id);
449 -- expose node_ids ???
450 -- -- cannot mention the same table twice in a join ?
451 -- -- CREATE OR REPLACE VIEW ilink_src_node AS
453 -- ilink.tag_type_id,
454 -- ilink.src_interface_id,
455 -- interfaces.node_id AS src_node_id,
456 -- ilink.dst_interface_id
458 -- INNER JOIN interfaces ON ilink.src_interface_id = interfaces.interface_id;
460 -- CREATE OR REPLACE VIEW ilink_nodes AS
463 -- interfaces.node_id as dst_node_id
464 -- FROM ilink_src_node
465 -- INNER JOIN interfaces ON ilink_src_node.dst_interface_id = interfaces.interface_id;
467 --------------------------------------------------------------------------------
469 --------------------------------------------------------------------------------
472 CREATE TABLE nodegroups (
473 nodegroup_id serial PRIMARY KEY, -- Group identifier
474 groupname text UNIQUE NOT NULL, -- Group name
475 tag_type_id integer REFERENCES tag_types, -- node is in nodegroup if it has this tag defined
476 -- can be null, make management faster & easier
477 tagvalue text -- with this value attached
480 -- xxx - first rough implem. similar to former semantics but might be slow
481 CREATE OR REPLACE VIEW nodegroup_node AS
482 SELECT nodegroup_id, node_id
487 USING (tag_type_id,tagvalue);
489 CREATE OR REPLACE VIEW nodegroup_nodes AS
491 array_accum(node_id) AS node_ids
493 GROUP BY nodegroup_id;
495 -- Node groups that each node is a member of
496 CREATE OR REPLACE VIEW node_nodegroups AS
498 array_accum(nodegroup_id) AS nodegroup_ids
502 --------------------------------------------------------------------------------
503 -- Node configuration files
504 --------------------------------------------------------------------------------
506 CREATE TABLE conf_files (
507 conf_file_id serial PRIMARY KEY, -- Configuration file identifier
508 enabled bool NOT NULL DEFAULT true, -- Configuration file is active
509 source text NOT NULL, -- Relative path on the boot server
510 -- where file can be downloaded
511 dest text NOT NULL, -- Absolute path where file should be installed
512 file_permissions text NOT NULL DEFAULT '0644', -- chmod(1) permissions
513 file_owner text NOT NULL DEFAULT 'root', -- chown(1) owner
514 file_group text NOT NULL DEFAULT 'root', -- chgrp(1) owner
515 preinstall_cmd text, -- Shell command to execute prior to installing
516 postinstall_cmd text, -- Shell command to execute after installing
517 error_cmd text, -- Shell command to execute if any error occurs
518 ignore_cmd_errors bool NOT NULL DEFAULT false, -- Install file anyway even if an error occurs
519 always_update bool NOT NULL DEFAULT false -- Always attempt to install file even if unchanged
522 CREATE TABLE conf_file_node (
523 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
524 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
525 PRIMARY KEY (conf_file_id, node_id)
527 CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
528 CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
530 -- Nodes linked to each configuration file
531 CREATE OR REPLACE VIEW conf_file_nodes AS
533 array_accum(node_id) AS node_ids
535 GROUP BY conf_file_id;
537 -- Configuration files linked to each node
538 CREATE OR REPLACE VIEW node_conf_files AS
540 array_accum(conf_file_id) AS conf_file_ids
544 CREATE TABLE conf_file_nodegroup (
545 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
546 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Node group identifier
547 PRIMARY KEY (conf_file_id, nodegroup_id)
549 CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
550 CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
552 -- Node groups linked to each configuration file
553 CREATE OR REPLACE VIEW conf_file_nodegroups AS
555 array_accum(nodegroup_id) AS nodegroup_ids
556 FROM conf_file_nodegroup
557 GROUP BY conf_file_id;
559 -- Configuration files linked to each node group
560 CREATE OR REPLACE VIEW nodegroup_conf_files AS
562 array_accum(conf_file_id) AS conf_file_ids
563 FROM conf_file_nodegroup
564 GROUP BY nodegroup_id;
566 --------------------------------------------------------------------------------
567 -- Power control units (PCUs)
568 --------------------------------------------------------------------------------
572 pcu_id serial PRIMARY KEY, -- PCU identifier
573 site_id integer REFERENCES sites NOT NULL, -- Site identifier
574 hostname text, -- Hostname, not necessarily unique
575 -- (multiple logical sites could use the same PCU)
576 ip text NOT NULL, -- IP, not necessarily unique
579 protocol text, -- Protocol, e.g. ssh or https or telnet
580 username text, -- Username, if applicable
581 "password" text, -- Password, if applicable
582 model text, -- Model, e.g. BayTech or iPal
583 notes text -- Random notes
585 CREATE INDEX pcus_site_id_idx ON pcus (site_id);
587 CREATE OR REPLACE VIEW site_pcus AS
589 array_accum(pcu_id) AS pcu_ids
593 CREATE TABLE pcu_node (
594 pcu_id integer REFERENCES pcus NOT NULL, -- PCU identifier
595 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
596 port integer NOT NULL, -- Port number
597 PRIMARY KEY (pcu_id, node_id), -- The same node cannot be controlled by different ports
598 UNIQUE (pcu_id, port) -- The same port cannot control multiple nodes
600 CREATE INDEX pcu_node_pcu_id_idx ON pcu_node (pcu_id);
601 CREATE INDEX pcu_node_node_id_idx ON pcu_node (node_id);
603 CREATE OR REPLACE VIEW node_pcus AS
605 array_accum(pcu_id) AS pcu_ids,
606 array_accum(port) AS ports
610 CREATE OR REPLACE VIEW pcu_nodes AS
612 array_accum(node_id) AS node_ids,
613 array_accum(port) AS ports
617 --------------------------------------------------------------------------------
619 --------------------------------------------------------------------------------
621 CREATE TABLE slice_instantiations (
622 instantiation text PRIMARY KEY
624 INSERT INTO slice_instantiations (instantiation) VALUES
625 ('not-instantiated'), -- Placeholder slice
626 ('plc-instantiated'), -- Instantiated by Node Manager
627 ('delegated'), -- Manually instantiated
628 ('nm-controller'); -- NM Controller
631 CREATE TABLE slices (
632 slice_id serial PRIMARY KEY, -- Slice identifier
633 site_id integer REFERENCES sites NOT NULL, -- Site identifier
635 name text NOT NULL, -- Slice name
636 instantiation text REFERENCES slice_instantiations -- Slice state, e.g. plc-instantiated
637 NOT NULL DEFAULT 'plc-instantiated',
638 url text, -- Project URL
639 description text, -- Project description
641 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
643 creator_person_id integer REFERENCES persons, -- Creator
644 created timestamp without time zone NOT NULL -- Creation date
645 DEFAULT CURRENT_TIMESTAMP,
646 expires timestamp without time zone NOT NULL -- Expiration date
647 DEFAULT CURRENT_TIMESTAMP + '2 weeks',
649 is_deleted boolean NOT NULL DEFAULT false
651 CREATE INDEX slices_site_id_idx ON slices (site_id);
652 CREATE INDEX slices_name_idx ON slices (name);
655 CREATE TABLE slice_node (
656 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
657 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
658 PRIMARY KEY (slice_id, node_id)
660 CREATE INDEX slice_node_slice_id_idx ON slice_node (slice_id);
661 CREATE INDEX slice_node_node_id_idx ON slice_node (node_id);
663 -- Synonym for slice_node
664 CREATE OR REPLACE VIEW slivers AS
665 SELECT * FROM slice_node;
667 -- Nodes in each slice
668 CREATE OR REPLACE VIEW slice_nodes AS
670 array_accum(node_id) AS node_ids
674 -- Slices on each node
675 CREATE OR REPLACE VIEW node_slices AS
677 array_accum(slice_id) AS slice_ids
681 -- Slices at each site
682 CREATE OR REPLACE VIEW site_slices AS
684 array_accum(slice_id) AS slice_ids
686 WHERE is_deleted is false
690 CREATE TABLE slice_person (
691 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
692 person_id integer REFERENCES persons NOT NULL, -- Account identifier
693 PRIMARY KEY (slice_id, person_id)
695 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
696 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
698 -- Members of the slice
699 CREATE OR REPLACE VIEW slice_persons AS
701 array_accum(person_id) AS person_ids
705 -- Slices of which each person is a member
706 CREATE OR REPLACE VIEW person_slices AS
708 array_accum(slice_id) AS slice_ids
712 --------------------------------------------------------------------------------
714 --------------------------------------------------------------------------------
715 -- slice whitelist on nodes
716 CREATE TABLE node_slice_whitelist (
717 node_id integer REFERENCES nodes NOT NULL, -- Node id of whitelist
718 slice_id integer REFERENCES slices NOT NULL, -- Slice id thats allowd on this node
719 PRIMARY KEY (node_id, slice_id)
721 CREATE INDEX node_slice_whitelist_node_id_idx ON node_slice_whitelist (node_id);
722 CREATE INDEX node_slice_whitelist_slice_id_idx ON node_slice_whitelist (slice_id);
724 -- Slices on each node
725 CREATE OR REPLACE VIEW node_slices_whitelist AS
727 array_accum(slice_id) AS slice_ids_whitelist
728 FROM node_slice_whitelist
731 --------------------------------------------------------------------------------
733 --------------------------------------------------------------------------------
735 -- Slice/sliver attributes
736 CREATE TABLE slice_attribute (
737 slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
738 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
739 node_id integer REFERENCES nodes, -- Sliver attribute if set
740 nodegroup_id integer REFERENCES nodegroups, -- Node group attribute if set
741 tag_type_id integer REFERENCES tag_types NOT NULL, -- Attribute type identifier
744 CREATE INDEX slice_attribute_slice_id_idx ON slice_attribute (slice_id);
745 CREATE INDEX slice_attribute_node_id_idx ON slice_attribute (node_id);
746 CREATE INDEX slice_attribute_nodegroup_id_idx ON slice_attribute (nodegroup_id);
748 CREATE OR REPLACE VIEW slice_attributes AS
750 array_accum(slice_attribute_id) AS slice_attribute_ids
754 --------------------------------------------------------------------------------
756 --------------------------------------------------------------------------------
759 CREATE TABLE initscripts (
760 initscript_id serial PRIMARY KEY, -- Initscript identifier
761 name text NOT NULL, -- Initscript name
762 enabled bool NOT NULL DEFAULT true, -- Initscript is active
763 script text NOT NULL, -- Initscript body
766 CREATE INDEX initscripts_name_idx ON initscripts (name);
769 --------------------------------------------------------------------------------
771 --------------------------------------------------------------------------------
775 peer_id serial PRIMARY KEY, -- Peer identifier
776 peername text NOT NULL, -- Peer name
777 peer_url text NOT NULL, -- (HTTPS) URL of the peer PLCAPI interface
778 cacert text, -- (SSL) Public certificate of peer API server
779 key text, -- (GPG) Public key used for authentication
780 deleted boolean NOT NULL DEFAULT false
782 CREATE INDEX peers_peername_idx ON peers (peername) WHERE deleted IS false;
784 -- Objects at each peer
785 CREATE TABLE peer_site (
786 site_id integer REFERENCES sites PRIMARY KEY, -- Local site identifier
787 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
788 peer_site_id integer NOT NULL, -- Foreign site identifier at peer
789 UNIQUE (peer_id, peer_site_id) -- The same foreign site should not be cached twice
791 CREATE INDEX peer_site_peer_id_idx ON peers (peer_id);
793 CREATE OR REPLACE VIEW peer_sites AS
795 array_accum(site_id) AS site_ids,
796 array_accum(peer_site_id) AS peer_site_ids
800 CREATE TABLE peer_person (
801 person_id integer REFERENCES persons PRIMARY KEY, -- Local user identifier
802 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
803 peer_person_id integer NOT NULL, -- Foreign user identifier at peer
804 UNIQUE (peer_id, peer_person_id) -- The same foreign user should not be cached twice
806 CREATE INDEX peer_person_peer_id_idx ON peer_person (peer_id);
808 CREATE OR REPLACE VIEW peer_persons AS
810 array_accum(person_id) AS person_ids,
811 array_accum(peer_person_id) AS peer_person_ids
815 CREATE TABLE peer_key (
816 key_id integer REFERENCES keys PRIMARY KEY, -- Local key identifier
817 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
818 peer_key_id integer NOT NULL, -- Foreign key identifier at peer
819 UNIQUE (peer_id, peer_key_id) -- The same foreign key should not be cached twice
821 CREATE INDEX peer_key_peer_id_idx ON peer_key (peer_id);
823 CREATE OR REPLACE VIEW peer_keys AS
825 array_accum(key_id) AS key_ids,
826 array_accum(peer_key_id) AS peer_key_ids
830 CREATE TABLE peer_node (
831 node_id integer REFERENCES nodes PRIMARY KEY, -- Local node identifier
832 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
833 peer_node_id integer NOT NULL, -- Foreign node identifier
834 UNIQUE (peer_id, peer_node_id) -- The same foreign node should not be cached twice
836 CREATE INDEX peer_node_peer_id_idx ON peer_node (peer_id);
838 CREATE OR REPLACE VIEW peer_nodes AS
840 array_accum(node_id) AS node_ids,
841 array_accum(peer_node_id) AS peer_node_ids
845 CREATE TABLE peer_slice (
846 slice_id integer REFERENCES slices PRIMARY KEY, -- Local slice identifier
847 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
848 peer_slice_id integer NOT NULL, -- Slice identifier at peer
849 UNIQUE (peer_id, peer_slice_id) -- The same foreign slice should not be cached twice
851 CREATE INDEX peer_slice_peer_id_idx ON peer_slice (peer_id);
853 CREATE OR REPLACE VIEW peer_slices AS
855 array_accum(slice_id) AS slice_ids,
856 array_accum(peer_slice_id) AS peer_slice_ids
860 --------------------------------------------------------------------------------
861 -- Authenticated sessions
862 --------------------------------------------------------------------------------
864 -- Authenticated sessions
865 CREATE TABLE sessions (
866 session_id text PRIMARY KEY, -- Session identifier
867 expires timestamp without time zone
870 -- People can have multiple sessions
871 CREATE TABLE person_session (
872 person_id integer REFERENCES persons NOT NULL, -- Account identifier
873 session_id text REFERENCES sessions NOT NULL, -- Session identifier
874 PRIMARY KEY (person_id, session_id),
875 UNIQUE (session_id) -- Sessions are unique
877 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
879 -- Nodes can have only one session
880 CREATE TABLE node_session (
881 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
882 session_id text REFERENCES sessions NOT NULL, -- Session identifier
883 UNIQUE (node_id), -- Nodes can have only one session
884 UNIQUE (session_id) -- Sessions are unique
887 -------------------------------------------------------------------------------
889 ------------------------------------------------------------------------------
890 CREATE TABLE pcu_types (
891 pcu_type_id serial PRIMARY KEY,
892 model text NOT NULL , -- PCU model name
893 name text -- Full PCU model name
895 CREATE INDEX pcu_types_model_idx ON pcu_types (model);
897 CREATE TABLE pcu_protocol_type (
898 pcu_protocol_type_id serial PRIMARY KEY,
899 pcu_type_id integer REFERENCES pcu_types NOT NULL, -- PCU type identifier
900 port integer NOT NULL, -- PCU port
901 protocol text NOT NULL, -- Protocol
902 supported boolean NOT NULL DEFAULT True -- Does PLC support
904 CREATE INDEX pcu_protocol_type_pcu_type_id ON pcu_protocol_type (pcu_type_id);
907 CREATE OR REPLACE VIEW pcu_protocol_types AS
909 array_accum(pcu_protocol_type_id) as pcu_protocol_type_ids
910 FROM pcu_protocol_type
911 GROUP BY pcu_type_id;
913 --------------------------------------------------------------------------------
915 --------------------------------------------------------------------------------
917 CREATE TABLE messages (
918 message_id text PRIMARY KEY, -- Message name
919 subject text, -- Message summary
920 template text, -- Message template
921 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
924 --------------------------------------------------------------------------------
926 --------------------------------------------------------------------------------
929 CREATE TABLE events (
930 event_id serial PRIMARY KEY, -- Event identifier
931 person_id integer REFERENCES persons, -- Person responsible for event, if any
932 node_id integer REFERENCES nodes, -- Node responsible for event, if any
933 auth_type text, -- Type of auth used. i.e. AuthMethod
934 fault_code integer NOT NULL DEFAULT 0, -- Did this event result in error
935 call_name text NOT NULL, -- Call responsible for this event
936 call text NOT NULL, -- Call responsible for this event, including parameters
937 message text, -- High level description of this event
938 runtime float DEFAULT 0, -- Event run time
939 time timestamp without time zone NOT NULL -- Event timestamp
940 DEFAULT CURRENT_TIMESTAMP
943 -- Database object(s) that may have been affected by a particular event
944 CREATE TABLE event_object (
945 event_id integer REFERENCES events NOT NULL, -- Event identifier
946 object_id integer NOT NULL, -- Object identifier
947 object_type text NOT NULL Default 'Unknown' -- What type of object is this event affecting
949 CREATE INDEX event_object_event_id_idx ON event_object (event_id);
950 CREATE INDEX event_object_object_id_idx ON event_object (object_id);
951 CREATE INDEX event_object_object_type_idx ON event_object (object_type);
953 CREATE OR REPLACE VIEW event_objects AS
955 array_accum(object_id) AS object_ids,
956 array_accum(object_type) AS object_types
960 --------------------------------------------------------------------------------
962 --------------------------------------------------------------------------------
963 CREATE OR REPLACE VIEW view_pcu_types AS
965 pcu_types.pcu_type_id,
968 COALESCE((SELECT pcu_protocol_type_ids FROM pcu_protocol_types
969 WHERE pcu_protocol_types.pcu_type_id = pcu_types.pcu_type_id), '{}')
970 AS pcu_protocol_type_ids
973 CREATE OR REPLACE VIEW view_events AS
984 CAST(date_part('epoch', events.time) AS bigint) AS time,
985 COALESCE((SELECT object_ids FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_ids,
986 COALESCE((SELECT object_types FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_types
989 CREATE OR REPLACE VIEW view_event_objects AS
999 CAST(date_part('epoch', events.time) AS bigint) AS time,
1000 event_object.object_id,
1001 event_object.object_type
1002 FROM events LEFT JOIN event_object USING (event_id);
1004 CREATE OR REPLACE VIEW view_persons AS
1013 persons.verification_key,
1014 CAST(date_part('epoch', persons.verification_expires) AS bigint) AS verification_expires,
1019 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
1020 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
1021 peer_person.peer_id,
1022 peer_person.peer_person_id,
1023 COALESCE((SELECT role_ids FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS role_ids,
1024 COALESCE((SELECT roles FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS roles,
1025 COALESCE((SELECT site_ids FROM person_sites WHERE person_sites.person_id = persons.person_id), '{}') AS site_ids,
1026 COALESCE((SELECT key_ids FROM person_keys WHERE person_keys.person_id = persons.person_id), '{}') AS key_ids,
1027 COALESCE((SELECT slice_ids FROM person_slices WHERE person_slices.person_id = persons.person_id), '{}') AS slice_ids
1029 LEFT JOIN peer_person USING (person_id);
1031 CREATE OR REPLACE VIEW view_peers AS
1034 COALESCE((SELECT site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS site_ids,
1035 COALESCE((SELECT peer_site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS peer_site_ids,
1036 COALESCE((SELECT person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS person_ids,
1037 COALESCE((SELECT peer_person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS peer_person_ids,
1038 COALESCE((SELECT key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS key_ids,
1039 COALESCE((SELECT peer_key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS peer_key_ids,
1040 COALESCE((SELECT node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS node_ids,
1041 COALESCE((SELECT peer_node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS peer_node_ids,
1042 COALESCE((SELECT slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS slice_ids,
1043 COALESCE((SELECT peer_slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS peer_slice_ids
1046 CREATE OR REPLACE VIEW view_nodes AS
1058 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
1059 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
1060 CAST(date_part('epoch', nodes.last_contact) AS bigint) AS last_contact,
1062 peer_node.peer_node_id,
1063 COALESCE((SELECT interface_ids FROM node_interfaces
1064 WHERE node_interfaces.node_id = nodes.node_id), '{}')
1066 COALESCE((SELECT nodegroup_ids FROM node_nodegroups
1067 WHERE node_nodegroups.node_id = nodes.node_id), '{}')
1069 COALESCE((SELECT slice_ids FROM node_slices
1070 WHERE node_slices.node_id = nodes.node_id), '{}')
1072 COALESCE((SELECT slice_ids_whitelist FROM node_slices_whitelist
1073 WHERE node_slices_whitelist.node_id = nodes.node_id), '{}')
1074 AS slice_ids_whitelist,
1075 COALESCE((SELECT pcu_ids FROM node_pcus
1076 WHERE node_pcus.node_id = nodes.node_id), '{}')
1078 COALESCE((SELECT ports FROM node_pcus
1079 WHERE node_pcus.node_id = nodes.node_id), '{}')
1081 COALESCE((SELECT conf_file_ids FROM node_conf_files
1082 WHERE node_conf_files.node_id = nodes.node_id), '{}')
1084 COALESCE((SELECT tag_ids FROM node_tags
1085 WHERE node_tags.node_id = nodes.node_id), '{}')
1087 node_session.session_id AS session
1089 LEFT JOIN peer_node USING (node_id)
1090 LEFT JOIN node_session USING (node_id);
1092 CREATE OR REPLACE VIEW view_nodegroups AS
1096 COALESCE((SELECT conf_file_ids FROM nodegroup_conf_files
1097 WHERE nodegroup_conf_files.nodegroup_id = nodegroups.nodegroup_id), '{}')
1099 COALESCE((SELECT node_ids FROM nodegroup_nodes
1100 WHERE nodegroup_nodes.nodegroup_id = nodegroups.nodegroup_id), '{}')
1102 FROM nodegroups INNER JOIN tag_types USING (tag_type_id);
1104 CREATE OR REPLACE VIEW view_conf_files AS
1107 COALESCE((SELECT node_ids FROM conf_file_nodes
1108 WHERE conf_file_nodes.conf_file_id = conf_files.conf_file_id), '{}')
1110 COALESCE((SELECT nodegroup_ids FROM conf_file_nodegroups
1111 WHERE conf_file_nodegroups.conf_file_id = conf_files.conf_file_id), '{}')
1115 CREATE OR REPLACE VIEW view_pcus AS
1118 COALESCE((SELECT node_ids FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS node_ids,
1119 COALESCE((SELECT ports FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS ports
1122 CREATE OR REPLACE VIEW view_sites AS
1127 sites.abbreviated_name,
1136 sites.ext_consortium_id,
1137 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
1138 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
1140 peer_site.peer_site_id,
1141 COALESCE((SELECT person_ids FROM site_persons WHERE site_persons.site_id = sites.site_id), '{}') AS person_ids,
1142 COALESCE((SELECT node_ids FROM site_nodes WHERE site_nodes.site_id = sites.site_id), '{}') AS node_ids,
1143 COALESCE((SELECT address_ids FROM site_addresses WHERE site_addresses.site_id = sites.site_id), '{}') AS address_ids,
1144 COALESCE((SELECT slice_ids FROM site_slices WHERE site_slices.site_id = sites.site_id), '{}') AS slice_ids,
1145 COALESCE((SELECT pcu_ids FROM site_pcus WHERE site_pcus.site_id = sites.site_id), '{}') AS pcu_ids
1147 LEFT JOIN peer_site USING (site_id);
1149 CREATE OR REPLACE VIEW view_addresses AS
1152 COALESCE((SELECT address_type_ids FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_type_ids,
1153 COALESCE((SELECT address_types FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_types
1156 CREATE OR REPLACE VIEW view_keys AS
1159 person_key.person_id,
1161 peer_key.peer_key_id
1163 LEFT JOIN person_key USING (key_id)
1164 LEFT JOIN peer_key USING (key_id);
1166 CREATE OR REPLACE VIEW view_slices AS
1171 slices.instantiation,
1175 slices.creator_person_id,
1177 CAST(date_part('epoch', slices.created) AS bigint) AS created,
1178 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
1180 peer_slice.peer_slice_id,
1181 COALESCE((SELECT node_ids FROM slice_nodes WHERE slice_nodes.slice_id = slices.slice_id), '{}') AS node_ids,
1182 COALESCE((SELECT person_ids FROM slice_persons WHERE slice_persons.slice_id = slices.slice_id), '{}') AS person_ids,
1183 COALESCE((SELECT slice_attribute_ids FROM slice_attributes WHERE slice_attributes.slice_id = slices.slice_id), '{}') AS slice_attribute_ids
1185 LEFT JOIN peer_slice USING (slice_id);
1187 CREATE OR REPLACE VIEW view_slice_attributes AS
1189 slice_attribute.slice_attribute_id,
1190 slice_attribute.slice_id,
1191 slice_attribute.node_id,
1192 slice_attribute.nodegroup_id,
1193 tag_types.tag_type_id,
1195 tag_types.description,
1197 tag_types.min_role_id,
1198 slice_attribute.value
1199 FROM slice_attribute
1200 INNER JOIN tag_types USING (tag_type_id);
1202 CREATE OR REPLACE VIEW view_sessions AS
1204 sessions.session_id,
1205 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
1206 person_session.person_id,
1207 node_session.node_id
1209 LEFT JOIN person_session USING (session_id)
1210 LEFT JOIN node_session USING (session_id);
1212 --------------------------------------------------------------------------------
1213 -- Built-in maintenance account and default site
1214 --------------------------------------------------------------------------------
1217 (first_name, last_name, email, password, enabled)
1219 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
1221 INSERT INTO person_role (person_id, role_id)
1222 VALUES (1, 10), (1, 20), (1, 30), (1, 40);
1225 (login_base, name, abbreviated_name, max_slices)
1227 ('pl', 'PlanetLab Central', 'PLC', 100);