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
13 -- NOTE: this file was first created for version 4.3, the filename might be confusing
19 SET client_encoding = 'UNICODE';
21 --------------------------------------------------------------------------------
23 --------------------------------------------------------------------------------
26 CREATE TABLE plc_db_version (
27 version integer NOT NULL,
28 subversion integer NOT NULL DEFAULT 0
31 -- the migration scripts do not use the major 'version' number
32 -- so 5.0 sets subversion at 100
33 -- in case your database misses the site and persons tags feature,
34 -- you might wish to first upgrade to 4.3-rc16 before moving to some 5.0
35 -- or run the up script here
36 -- http://svn.planet-lab.org/svn/PLCAPI/branches/4.3/migrations/
38 INSERT INTO plc_db_version (version, subversion) VALUES (5, 100);
40 --------------------------------------------------------------------------------
41 -- Aggregates and store procedures
42 --------------------------------------------------------------------------------
44 -- Like MySQL GROUP_CONCAT(), this function aggregates values into a
46 CREATE AGGREGATE array_accum (
48 basetype = anyelement,
53 --------------------------------------------------------------------------------
55 --------------------------------------------------------------------------------
57 -- Valid account roles
59 role_id integer PRIMARY KEY, -- Role identifier
60 name text UNIQUE NOT NULL -- Role symbolic name
62 INSERT INTO roles (role_id, name) VALUES (10, 'admin');
63 INSERT INTO roles (role_id, name) VALUES (20, 'pi');
64 INSERT INTO roles (role_id, name) VALUES (30, 'user');
65 INSERT INTO roles (role_id, name) VALUES (40, 'tech');
67 --------------------------------------------------------------------------------
68 -- The building block for attaching tags
69 --------------------------------------------------------------------------------
70 CREATE TABLE tag_types (
72 tag_type_id serial PRIMARY KEY, -- ID
73 tagname text UNIQUE NOT NULL, -- Tag Name
74 description text, -- Optional Description
75 min_role_id integer REFERENCES roles DEFAULT 10, -- set minimal role required
76 category text NOT NULL DEFAULT 'general' -- Free text for grouping tags together
79 --------------------------------------------------------------------------------
81 --------------------------------------------------------------------------------
84 CREATE TABLE persons (
86 person_id serial PRIMARY KEY, -- Account identifier
87 email text NOT NULL, -- E-mail address
88 first_name text NOT NULL, -- First name
89 last_name text NOT NULL, -- Last name
90 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
91 enabled boolean NOT NULL DEFAULT false, -- Has been disabled
93 password text NOT NULL DEFAULT 'nopass', -- Password (md5crypted)
94 verification_key text, -- Reset password key
95 verification_expires timestamp without time zone,
98 title text, -- Honorific
99 phone text, -- Telephone number
100 url text, -- Home page
101 bio text, -- Biography
104 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
105 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
107 CREATE INDEX persons_email_idx ON persons (email);
109 --------------------------------------------------------------------------------
111 --------------------------------------------------------------------------------
112 CREATE TABLE person_tag (
113 person_tag_id serial PRIMARY KEY, -- ID
114 person_id integer REFERENCES persons NOT NULL, -- person id
115 tag_type_id integer REFERENCES tag_types, -- tag type id
116 value text -- value attached
119 CREATE OR REPLACE VIEW person_tags AS
121 array_accum(person_tag_id) AS person_tag_ids
125 CREATE OR REPLACE VIEW view_person_tags AS
127 person_tag.person_tag_id,
128 person_tag.person_id,
130 tag_types.tag_type_id,
132 tag_types.description,
134 tag_types.min_role_id,
137 INNER JOIN tag_types USING (tag_type_id)
138 INNER JOIN persons USING (person_id);
140 --------------------------------------------------------------------------------
142 --------------------------------------------------------------------------------
147 site_id serial PRIMARY KEY, -- Site identifier
148 login_base text NOT NULL, -- Site slice prefix
149 name text NOT NULL, -- Site name
150 abbreviated_name text NOT NULL, -- Site abbreviated name
151 enabled boolean NOT NULL Default true, -- Is this site enabled
152 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
153 is_public boolean NOT NULL DEFAULT true, -- Shows up in public lists
154 max_slices integer NOT NULL DEFAULT 0, -- Maximum number of slices
155 max_slivers integer NOT NULL DEFAULT 1000, -- Maximum number of instantiated slivers
161 ext_consortium_id integer, -- external consortium id
164 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
165 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
167 CREATE INDEX sites_login_base_idx ON sites (login_base);
169 -- Account site membership
170 CREATE TABLE person_site (
171 person_id integer REFERENCES persons NOT NULL, -- Account identifier
172 site_id integer REFERENCES sites NOT NULL, -- Site identifier
173 is_primary boolean NOT NULL DEFAULT false, -- Is the primary site for this account
174 PRIMARY KEY (person_id, site_id)
176 CREATE INDEX person_site_person_id_idx ON person_site (person_id);
177 CREATE INDEX person_site_site_id_idx ON person_site (site_id);
179 -- Ordered by primary site first
180 CREATE OR REPLACE VIEW person_site_ordered AS
181 SELECT person_id, site_id
183 ORDER BY is_primary DESC;
185 -- Sites that each person is a member of
186 CREATE OR REPLACE VIEW person_sites AS
188 array_accum(site_id) AS site_ids
189 FROM person_site_ordered
192 -- Accounts at each site
193 CREATE OR REPLACE VIEW site_persons AS
195 array_accum(person_id) AS person_ids
199 --------------------------------------------------------------------------------
201 --------------------------------------------------------------------------------
203 CREATE TABLE site_tag (
204 site_tag_id serial PRIMARY KEY, -- ID
205 site_id integer REFERENCES sites NOT NULL, -- site id
206 tag_type_id integer REFERENCES tag_types, -- tag type id
207 value text -- value attached
210 CREATE OR REPLACE VIEW site_tags AS
212 array_accum(site_tag_id) AS site_tag_ids
216 CREATE OR REPLACE VIEW view_site_tags AS
218 site_tag.site_tag_id,
221 tag_types.tag_type_id,
223 tag_types.description,
225 tag_types.min_role_id,
228 INNER JOIN tag_types USING (tag_type_id)
229 INNER JOIN sites USING (site_id);
231 --------------------------------------------------------------------------------
233 --------------------------------------------------------------------------------
235 CREATE TABLE address_types (
236 address_type_id serial PRIMARY KEY, -- Address type identifier
237 name text UNIQUE NOT NULL, -- Address type
238 description text -- Address type description
241 -- Multi-rows insertion "insert .. values (row1), (row2)" is not supported by pgsql-8.1
242 -- 'Billing' Used to be 'Site'
243 INSERT INTO address_types (name) VALUES ('Personal');
244 INSERT INTO address_types (name) VALUES ('Shipping');
245 INSERT INTO address_types (name) VALUES ('Billing');
248 CREATE TABLE addresses (
249 address_id serial PRIMARY KEY, -- Address identifier
250 line1 text NOT NULL, -- Address line 1
251 line2 text, -- Address line 2
252 line3 text, -- Address line 3
253 city text NOT NULL, -- City
254 state text NOT NULL, -- State or province
255 postalcode text NOT NULL, -- Postal code
256 country text NOT NULL -- Country
259 -- Each mailing address can be one of several types
260 CREATE TABLE address_address_type (
261 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
262 address_type_id integer REFERENCES address_types NOT NULL, -- Address type
263 PRIMARY KEY (address_id, address_type_id)
265 CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
266 CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);
268 CREATE OR REPLACE VIEW address_address_types AS
270 array_accum(address_type_id) AS address_type_ids,
271 array_accum(address_types.name) AS address_types
272 FROM address_address_type
273 LEFT JOIN address_types USING (address_type_id)
276 CREATE TABLE site_address (
277 site_id integer REFERENCES sites NOT NULL, -- Site identifier
278 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
279 PRIMARY KEY (site_id, address_id)
281 CREATE INDEX site_address_site_id_idx ON site_address (site_id);
282 CREATE INDEX site_address_address_id_idx ON site_address (address_id);
284 CREATE OR REPLACE VIEW site_addresses AS
286 array_accum(address_id) AS address_ids
290 --------------------------------------------------------------------------------
291 -- Authentication Keys
292 --------------------------------------------------------------------------------
295 CREATE TABLE key_types (
296 key_type text PRIMARY KEY -- Key type
298 INSERT INTO key_types (key_type) VALUES ('ssh');
300 -- Authentication keys
302 key_id serial PRIMARY KEY, -- Key identifier
303 key_type text REFERENCES key_types NOT NULL, -- Key type
304 key text NOT NULL, -- Key material
305 is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
308 -- Account authentication key(s)
309 CREATE TABLE person_key (
310 key_id integer REFERENCES keys PRIMARY KEY, -- Key identifier
311 person_id integer REFERENCES persons NOT NULL -- Account identifier
313 CREATE INDEX person_key_person_id_idx ON person_key (person_id);
315 CREATE OR REPLACE VIEW person_keys AS
317 array_accum(key_id) AS key_ids
321 --------------------------------------------------------------------------------
323 --------------------------------------------------------------------------------
325 CREATE TABLE person_role (
326 person_id integer REFERENCES persons NOT NULL, -- Account identifier
327 role_id integer REFERENCES roles NOT NULL, -- Role identifier
328 PRIMARY KEY (person_id, role_id)
330 CREATE INDEX person_role_person_id_idx ON person_role (person_id);
333 CREATE OR REPLACE VIEW person_roles AS
335 array_accum(role_id) AS role_ids,
336 array_accum(roles.name) AS roles
338 LEFT JOIN roles USING (role_id)
341 --------------------------------------------------------------------------------
343 --------------------------------------------------------------------------------
345 -- Valid node boot states (Nodes.py expect max length to be 20)
346 CREATE TABLE boot_states (
347 boot_state text PRIMARY KEY
349 INSERT INTO boot_states (boot_state) VALUES ('boot');
350 INSERT INTO boot_states (boot_state) VALUES ('safeboot');
351 INSERT INTO boot_states (boot_state) VALUES ('reinstall');
352 INSERT INTO boot_states (boot_state) VALUES ('disabled');
354 CREATE TABLE run_levels (
355 run_level text PRIMARY KEY
357 INSERT INTO run_levels (run_level) VALUES ('boot');
358 INSERT INTO run_levels (run_level) VALUES ('safeboot');
359 INSERT INTO run_levels (run_level) VALUES ('failboot');
360 INSERT INTO run_levels (run_level) VALUES ('reinstall');
362 -- Known node types (Nodes.py expect max length to be 20)
363 CREATE TABLE node_types (
364 node_type text PRIMARY KEY
366 INSERT INTO node_types (node_type) VALUES ('regular');
367 -- old dummynet stuff, to be removed
368 INSERT INTO node_types (node_type) VALUES ('dummynet');
373 node_id serial PRIMARY KEY, -- Node identifier
374 node_type text REFERENCES node_types -- node type
377 hostname text NOT NULL, -- Node hostname
378 site_id integer REFERENCES sites NOT NULL, -- At which site
379 boot_state text REFERENCES boot_states NOT NULL -- Node boot state
381 run_level text REFERENCES run_levels DEFAULT NULL, -- Node Run Level
382 deleted boolean NOT NULL DEFAULT false, -- Is deleted
385 model text, -- Hardware make and model
386 boot_nonce text, -- Random nonce updated by Boot Manager
387 version text, -- Boot CD version string updated by Boot Manager
388 ssh_rsa_key text, -- SSH host key updated by Boot Manager
389 key text, -- Node key generated when boot file is downloaded
390 verified boolean NOT NULL DEFAULT false, -- whether or not the node & pcu are verified
393 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
394 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
395 last_contact timestamp without time zone
397 CREATE INDEX nodes_hostname_idx ON nodes (hostname);
398 CREATE INDEX nodes_site_id_idx ON nodes (site_id);
400 -- Nodes at each site
401 CREATE OR REPLACE VIEW site_nodes AS
403 array_accum(node_id) AS node_ids
405 WHERE deleted IS false
408 --------------------------------------------------------------------------------
410 --------------------------------------------------------------------------------
412 CREATE TABLE node_tag (
413 node_tag_id serial PRIMARY KEY, -- ID
414 node_id integer REFERENCES nodes NOT NULL, -- node id
415 tag_type_id integer REFERENCES tag_types, -- tag type id
416 value text -- value attached
419 --------------------------------------------------------------------------------
420 -- (network) interfaces
421 --------------------------------------------------------------------------------
423 -- Valid network addressing schemes
424 CREATE TABLE network_types (
425 type text PRIMARY KEY -- Addressing scheme
427 INSERT INTO network_types (type) VALUES ('ipv4');
429 -- Valid network configuration methods
430 CREATE TABLE network_methods (
431 method text PRIMARY KEY -- Configuration method
434 INSERT INTO network_methods (method) VALUES ('static');
435 INSERT INTO network_methods (method) VALUES ('dhcp');
436 INSERT INTO network_methods (method) VALUES ('proxy');
437 INSERT INTO network_methods (method) VALUES ('tap');
438 INSERT INTO network_methods (method) VALUES ('ipmi');
439 INSERT INTO network_methods (method) VALUES ('unknown');
441 -- Network interfaces
442 CREATE TABLE interfaces (
444 interface_id serial PRIMARY KEY, -- Network interface identifier
445 node_id integer REFERENCES nodes NOT NULL, -- Which node
446 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
447 type text REFERENCES network_types NOT NULL, -- Addressing scheme
448 method text REFERENCES network_methods NOT NULL, -- Configuration method
450 -- Optional, depending on type and method
451 ip text, -- IP address
452 mac text, -- MAC address
453 gateway text, -- Default gateway address
454 network text, -- Network address
455 broadcast text, -- Network broadcast address
456 netmask text, -- Network mask
457 dns1 text, -- Primary DNS server
458 dns2 text, -- Secondary DNS server
459 bwlimit integer, -- Bandwidth limit in bps
460 hostname text -- Hostname of this interface
462 CREATE INDEX interfaces_node_id_idx ON interfaces (node_id);
464 -- Ordered by primary interface first
465 CREATE OR REPLACE VIEW interfaces_ordered AS
466 SELECT node_id, interface_id
468 ORDER BY is_primary DESC;
470 -- Network interfaces on each node
471 CREATE OR REPLACE VIEW node_interfaces AS
473 array_accum(interface_id) AS interface_ids
474 FROM interfaces_ordered
477 --------------------------------------------------------------------------------
478 -- Interface tags (formerly known as interface settings)
479 --------------------------------------------------------------------------------
481 CREATE TABLE interface_tag (
482 interface_tag_id serial PRIMARY KEY, -- Interface Setting Identifier
483 interface_id integer REFERENCES interfaces NOT NULL,-- the interface this applies to
484 tag_type_id integer REFERENCES tag_types NOT NULL, -- the setting type
485 value text -- value attached
488 CREATE OR REPLACE VIEW interface_tags AS
490 array_accum(interface_tag_id) AS interface_tag_ids
492 GROUP BY interface_id;
494 CREATE OR REPLACE VIEW view_interface_tags AS
496 interface_tag.interface_tag_id,
497 interface_tag.interface_id,
499 tag_types.tag_type_id,
501 tag_types.description,
503 tag_types.min_role_id,
506 INNER JOIN tag_types USING (tag_type_id)
507 INNER JOIN interfaces USING (interface_id);
509 CREATE OR REPLACE VIEW view_interfaces AS
511 interfaces.interface_id,
513 interfaces.is_primary,
520 interfaces.broadcast,
526 COALESCE((SELECT interface_tag_ids FROM interface_tags WHERE interface_tags.interface_id = interfaces.interface_id), '{}') AS interface_tag_ids
529 --------------------------------------------------------------------------------
530 -- ilinks : links between interfaces
531 --------------------------------------------------------------------------------
533 ilink_id serial PRIMARY KEY, -- id
534 tag_type_id integer REFERENCES tag_types, -- id of the tag type
535 src_interface_id integer REFERENCES interfaces not NULL, -- id of src interface
536 dst_interface_id integer REFERENCES interfaces NOT NULL, -- id of dst interface
537 value text -- optional value on the link
540 CREATE OR REPLACE VIEW view_ilinks AS
541 SELECT * FROM tag_types
542 INNER JOIN ilink USING (tag_type_id);
544 -- xxx TODO : expose to view_interfaces the set of ilinks a given interface is part of
545 -- this is needed for properly deleting these ilinks when an interface gets deleted
546 -- as this is not done yet, it prevents DeleteInterface, thus DeleteNode, thus DeleteSite
547 -- from working correctly when an iLink is set
549 --------------------------------------------------------------------------------
551 --------------------------------------------------------------------------------
554 CREATE TABLE nodegroups (
555 nodegroup_id serial PRIMARY KEY, -- Group identifier
556 groupname text UNIQUE NOT NULL, -- Group name
557 tag_type_id integer REFERENCES tag_types, -- node is in nodegroup if it has this tag defined
558 -- can be null, make management faster & easier
559 value text -- with this value attached
562 -- xxx - first rough implem. similar to former semantics but might be slow
563 CREATE OR REPLACE VIEW nodegroup_node AS
564 SELECT nodegroup_id, node_id
569 USING (tag_type_id,value);
571 CREATE OR REPLACE VIEW nodegroup_nodes AS
573 array_accum(node_id) AS node_ids
575 GROUP BY nodegroup_id;
577 -- Node groups that each node is a member of
578 CREATE OR REPLACE VIEW node_nodegroups AS
580 array_accum(nodegroup_id) AS nodegroup_ids
584 --------------------------------------------------------------------------------
585 -- Node configuration files
586 --------------------------------------------------------------------------------
588 CREATE TABLE conf_files (
589 conf_file_id serial PRIMARY KEY, -- Configuration file identifier
590 enabled bool NOT NULL DEFAULT true, -- Configuration file is active
591 source text NOT NULL, -- Relative path on the boot server
592 -- where file can be downloaded
593 dest text NOT NULL, -- Absolute path where file should be installed
594 file_permissions text NOT NULL DEFAULT '0644', -- chmod(1) permissions
595 file_owner text NOT NULL DEFAULT 'root', -- chown(1) owner
596 file_group text NOT NULL DEFAULT 'root', -- chgrp(1) owner
597 preinstall_cmd text, -- Shell command to execute prior to installing
598 postinstall_cmd text, -- Shell command to execute after installing
599 error_cmd text, -- Shell command to execute if any error occurs
600 ignore_cmd_errors bool NOT NULL DEFAULT false, -- Install file anyway even if an error occurs
601 always_update bool NOT NULL DEFAULT false -- Always attempt to install file even if unchanged
604 CREATE TABLE conf_file_node (
605 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
606 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
607 PRIMARY KEY (conf_file_id, node_id)
609 CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
610 CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
612 -- Nodes linked to each configuration file
613 CREATE OR REPLACE VIEW conf_file_nodes AS
615 array_accum(node_id) AS node_ids
617 GROUP BY conf_file_id;
619 -- Configuration files linked to each node
620 CREATE OR REPLACE VIEW node_conf_files AS
622 array_accum(conf_file_id) AS conf_file_ids
626 CREATE TABLE conf_file_nodegroup (
627 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
628 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Node group identifier
629 PRIMARY KEY (conf_file_id, nodegroup_id)
631 CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
632 CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
634 -- Node groups linked to each configuration file
635 CREATE OR REPLACE VIEW conf_file_nodegroups AS
637 array_accum(nodegroup_id) AS nodegroup_ids
638 FROM conf_file_nodegroup
639 GROUP BY conf_file_id;
641 -- Configuration files linked to each node group
642 CREATE OR REPLACE VIEW nodegroup_conf_files AS
644 array_accum(conf_file_id) AS conf_file_ids
645 FROM conf_file_nodegroup
646 GROUP BY nodegroup_id;
648 --------------------------------------------------------------------------------
649 -- Power control units (PCUs)
650 --------------------------------------------------------------------------------
654 pcu_id serial PRIMARY KEY, -- PCU identifier
655 site_id integer REFERENCES sites NOT NULL, -- Site identifier
656 hostname text, -- Hostname, not necessarily unique
657 -- (multiple logical sites could use the same PCU)
658 ip text NOT NULL, -- IP, not necessarily unique
661 protocol text, -- Protocol, e.g. ssh or https or telnet
662 username text, -- Username, if applicable
663 "password" text, -- Password, if applicable
664 model text, -- Model, e.g. BayTech or iPal
665 notes text -- Random notes
667 CREATE INDEX pcus_site_id_idx ON pcus (site_id);
669 CREATE OR REPLACE VIEW site_pcus AS
671 array_accum(pcu_id) AS pcu_ids
675 CREATE TABLE pcu_node (
676 pcu_id integer REFERENCES pcus NOT NULL, -- PCU identifier
677 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
678 port integer NOT NULL, -- Port number
679 PRIMARY KEY (pcu_id, node_id), -- The same node cannot be controlled by different ports
680 UNIQUE (pcu_id, port) -- The same port cannot control multiple nodes
682 CREATE INDEX pcu_node_pcu_id_idx ON pcu_node (pcu_id);
683 CREATE INDEX pcu_node_node_id_idx ON pcu_node (node_id);
685 CREATE OR REPLACE VIEW node_pcus AS
687 array_accum(pcu_id) AS pcu_ids,
688 array_accum(port) AS ports
692 CREATE OR REPLACE VIEW pcu_nodes AS
694 array_accum(node_id) AS node_ids,
695 array_accum(port) AS ports
699 --------------------------------------------------------------------------------
701 --------------------------------------------------------------------------------
703 CREATE TABLE slice_instantiations (
704 instantiation text PRIMARY KEY
706 INSERT INTO slice_instantiations (instantiation) VALUES ('not-instantiated'); -- Placeholder slice
707 INSERT INTO slice_instantiations (instantiation) VALUES ('plc-instantiated'); -- Instantiated by Node Manager
708 INSERT INTO slice_instantiations (instantiation) VALUES ('delegated'); -- Manually instantiated
709 INSERT INTO slice_instantiations (instantiation) VALUES ('nm-controller'); -- NM Controller
712 CREATE TABLE slices (
713 slice_id serial PRIMARY KEY, -- Slice identifier
714 site_id integer REFERENCES sites NOT NULL, -- Site identifier
716 name text NOT NULL, -- Slice name
717 instantiation text REFERENCES slice_instantiations -- Slice state, e.g. plc-instantiated
718 NOT NULL DEFAULT 'plc-instantiated',
719 url text, -- Project URL
720 description text, -- Project description
722 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
724 creator_person_id integer REFERENCES persons, -- Creator
725 created timestamp without time zone NOT NULL -- Creation date
726 DEFAULT CURRENT_TIMESTAMP,
727 expires timestamp without time zone NOT NULL -- Expiration date
728 DEFAULT CURRENT_TIMESTAMP + '2 weeks',
730 is_deleted boolean NOT NULL DEFAULT false
732 CREATE INDEX slices_site_id_idx ON slices (site_id);
733 CREATE INDEX slices_name_idx ON slices (name);
736 CREATE TABLE slice_node (
737 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
738 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
739 PRIMARY KEY (slice_id, node_id)
741 CREATE INDEX slice_node_slice_id_idx ON slice_node (slice_id);
742 CREATE INDEX slice_node_node_id_idx ON slice_node (node_id);
744 -- Synonym for slice_node
745 CREATE OR REPLACE VIEW slivers AS
746 SELECT * FROM slice_node;
748 -- Nodes in each slice
749 CREATE OR REPLACE VIEW slice_nodes AS
751 array_accum(node_id) AS node_ids
755 -- Slices on each node
756 CREATE OR REPLACE VIEW node_slices AS
758 array_accum(slice_id) AS slice_ids
762 -- Slices at each site
763 CREATE OR REPLACE VIEW site_slices AS
765 array_accum(slice_id) AS slice_ids
767 WHERE is_deleted is false
771 CREATE TABLE slice_person (
772 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
773 person_id integer REFERENCES persons NOT NULL, -- Account identifier
774 PRIMARY KEY (slice_id, person_id)
776 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
777 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
779 -- Members of the slice
780 CREATE OR REPLACE VIEW slice_persons AS
782 array_accum(person_id) AS person_ids
786 -- Slices of which each person is a member
787 CREATE OR REPLACE VIEW person_slices AS
789 array_accum(slice_id) AS slice_ids
793 --------------------------------------------------------------------------------
795 --------------------------------------------------------------------------------
796 -- slice whitelist on nodes
797 CREATE TABLE node_slice_whitelist (
798 node_id integer REFERENCES nodes NOT NULL, -- Node id of whitelist
799 slice_id integer REFERENCES slices NOT NULL, -- Slice id thats allowd on this node
800 PRIMARY KEY (node_id, slice_id)
802 CREATE INDEX node_slice_whitelist_node_id_idx ON node_slice_whitelist (node_id);
803 CREATE INDEX node_slice_whitelist_slice_id_idx ON node_slice_whitelist (slice_id);
805 -- Slices on each node
806 CREATE OR REPLACE VIEW node_slices_whitelist AS
808 array_accum(slice_id) AS slice_ids_whitelist
809 FROM node_slice_whitelist
812 --------------------------------------------------------------------------------
813 -- Slice tags (formerly known as slice attributes)
814 --------------------------------------------------------------------------------
816 -- Slice/sliver attributes
817 CREATE TABLE slice_tag (
818 slice_tag_id serial PRIMARY KEY, -- Slice attribute identifier
819 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
820 node_id integer REFERENCES nodes, -- Sliver attribute if set
821 nodegroup_id integer REFERENCES nodegroups, -- Node group attribute if set
822 tag_type_id integer REFERENCES tag_types NOT NULL, -- Attribute type identifier
825 CREATE INDEX slice_tag_slice_id_idx ON slice_tag (slice_id);
826 CREATE INDEX slice_tag_node_id_idx ON slice_tag (node_id);
827 CREATE INDEX slice_tag_nodegroup_id_idx ON slice_tag (nodegroup_id);
829 --------------------------------------------------------------------------------
831 --------------------------------------------------------------------------------
834 CREATE TABLE initscripts (
835 initscript_id serial PRIMARY KEY, -- Initscript identifier
836 name text NOT NULL, -- Initscript name
837 enabled bool NOT NULL DEFAULT true, -- Initscript is active
838 script text NOT NULL, -- Initscript body
841 CREATE INDEX initscripts_name_idx ON initscripts (name);
844 --------------------------------------------------------------------------------
846 --------------------------------------------------------------------------------
850 peer_id serial PRIMARY KEY, -- Peer identifier
851 peername text NOT NULL, -- Peer name
852 peer_url text NOT NULL, -- (HTTPS) URL of the peer PLCAPI interface
853 cacert text, -- (SSL) Public certificate of peer API server
854 key text, -- (GPG) Public key used for authentication
855 shortname text, -- abbreviated name for displaying foreign objects
856 hrn_root text, -- root for this peer domain
857 deleted boolean NOT NULL DEFAULT false
859 CREATE INDEX peers_peername_idx ON peers (peername) WHERE deleted IS false;
860 CREATE INDEX peers_shortname_idx ON peers (shortname) WHERE deleted IS false;
862 -- Objects at each peer
863 CREATE TABLE peer_site (
864 site_id integer REFERENCES sites PRIMARY KEY, -- Local site identifier
865 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
866 peer_site_id integer NOT NULL, -- Foreign site identifier at peer
867 UNIQUE (peer_id, peer_site_id) -- The same foreign site should not be cached twice
869 CREATE INDEX peer_site_peer_id_idx ON peers (peer_id);
871 CREATE OR REPLACE VIEW peer_sites AS
873 array_accum(site_id) AS site_ids,
874 array_accum(peer_site_id) AS peer_site_ids
878 CREATE TABLE peer_person (
879 person_id integer REFERENCES persons PRIMARY KEY, -- Local user identifier
880 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
881 peer_person_id integer NOT NULL, -- Foreign user identifier at peer
882 UNIQUE (peer_id, peer_person_id) -- The same foreign user should not be cached twice
884 CREATE INDEX peer_person_peer_id_idx ON peer_person (peer_id);
886 CREATE OR REPLACE VIEW peer_persons AS
888 array_accum(person_id) AS person_ids,
889 array_accum(peer_person_id) AS peer_person_ids
893 CREATE TABLE peer_key (
894 key_id integer REFERENCES keys PRIMARY KEY, -- Local key identifier
895 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
896 peer_key_id integer NOT NULL, -- Foreign key identifier at peer
897 UNIQUE (peer_id, peer_key_id) -- The same foreign key should not be cached twice
899 CREATE INDEX peer_key_peer_id_idx ON peer_key (peer_id);
901 CREATE OR REPLACE VIEW peer_keys AS
903 array_accum(key_id) AS key_ids,
904 array_accum(peer_key_id) AS peer_key_ids
908 CREATE TABLE peer_node (
909 node_id integer REFERENCES nodes PRIMARY KEY, -- Local node identifier
910 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
911 peer_node_id integer NOT NULL, -- Foreign node identifier
912 UNIQUE (peer_id, peer_node_id) -- The same foreign node should not be cached twice
914 CREATE INDEX peer_node_peer_id_idx ON peer_node (peer_id);
916 CREATE OR REPLACE VIEW peer_nodes AS
918 array_accum(node_id) AS node_ids,
919 array_accum(peer_node_id) AS peer_node_ids
923 CREATE TABLE peer_slice (
924 slice_id integer REFERENCES slices PRIMARY KEY, -- Local slice identifier
925 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
926 peer_slice_id integer NOT NULL, -- Slice identifier at peer
927 UNIQUE (peer_id, peer_slice_id) -- The same foreign slice should not be cached twice
929 CREATE INDEX peer_slice_peer_id_idx ON peer_slice (peer_id);
931 CREATE OR REPLACE VIEW peer_slices AS
933 array_accum(slice_id) AS slice_ids,
934 array_accum(peer_slice_id) AS peer_slice_ids
938 --------------------------------------------------------------------------------
939 -- Authenticated sessions
940 --------------------------------------------------------------------------------
942 -- Authenticated sessions
943 CREATE TABLE sessions (
944 session_id text PRIMARY KEY, -- Session identifier
945 expires timestamp without time zone
948 -- People can have multiple sessions
949 CREATE TABLE person_session (
950 person_id integer REFERENCES persons NOT NULL, -- Account identifier
951 session_id text REFERENCES sessions NOT NULL, -- Session identifier
952 PRIMARY KEY (person_id, session_id),
953 UNIQUE (session_id) -- Sessions are unique
955 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
957 -- Nodes can have only one session
958 CREATE TABLE node_session (
959 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
960 session_id text REFERENCES sessions NOT NULL, -- Session identifier
961 UNIQUE (node_id), -- Nodes can have only one session
962 UNIQUE (session_id) -- Sessions are unique
965 -------------------------------------------------------------------------------
967 ------------------------------------------------------------------------------
968 CREATE TABLE pcu_types (
969 pcu_type_id serial PRIMARY KEY,
970 model text NOT NULL , -- PCU model name
971 name text -- Full PCU model name
973 CREATE INDEX pcu_types_model_idx ON pcu_types (model);
975 CREATE TABLE pcu_protocol_type (
976 pcu_protocol_type_id serial PRIMARY KEY,
977 pcu_type_id integer REFERENCES pcu_types NOT NULL, -- PCU type identifier
978 port integer NOT NULL, -- PCU port
979 protocol text NOT NULL, -- Protocol
980 supported boolean NOT NULL DEFAULT True -- Does PLC support
982 CREATE INDEX pcu_protocol_type_pcu_type_id ON pcu_protocol_type (pcu_type_id);
985 CREATE OR REPLACE VIEW pcu_protocol_types AS
987 array_accum(pcu_protocol_type_id) as pcu_protocol_type_ids
988 FROM pcu_protocol_type
989 GROUP BY pcu_type_id;
991 --------------------------------------------------------------------------------
993 --------------------------------------------------------------------------------
995 CREATE TABLE messages (
996 message_id text PRIMARY KEY, -- Message name
997 subject text, -- Message summary
998 template text, -- Message template
999 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
1002 --------------------------------------------------------------------------------
1004 --------------------------------------------------------------------------------
1007 CREATE TABLE events (
1008 event_id serial PRIMARY KEY, -- Event identifier
1009 person_id integer REFERENCES persons, -- Person responsible for event, if any
1010 node_id integer REFERENCES nodes, -- Node responsible for event, if any
1011 auth_type text, -- Type of auth used. i.e. AuthMethod
1012 fault_code integer NOT NULL DEFAULT 0, -- Did this event result in error
1013 call_name text NOT NULL, -- Call responsible for this event
1014 call text NOT NULL, -- Call responsible for this event, including parameters
1015 message text, -- High level description of this event
1016 runtime float DEFAULT 0, -- Event run time
1017 time timestamp without time zone NOT NULL -- Event timestamp
1018 DEFAULT CURRENT_TIMESTAMP
1021 -- Database object(s) that may have been affected by a particular event
1022 CREATE TABLE event_object (
1023 event_id integer REFERENCES events NOT NULL, -- Event identifier
1024 object_id integer NOT NULL, -- Object identifier
1025 object_type text NOT NULL Default 'Unknown' -- What type of object is this event affecting
1027 CREATE INDEX event_object_event_id_idx ON event_object (event_id);
1028 CREATE INDEX event_object_object_id_idx ON event_object (object_id);
1029 CREATE INDEX event_object_object_type_idx ON event_object (object_type);
1031 CREATE OR REPLACE VIEW event_objects AS
1033 array_accum(object_id) AS object_ids,
1034 array_accum(object_type) AS object_types
1038 --------------------------------------------------------------------------------
1040 --------------------------------------------------------------------------------
1041 CREATE OR REPLACE VIEW view_pcu_types AS
1043 pcu_types.pcu_type_id,
1046 COALESCE((SELECT pcu_protocol_type_ids FROM pcu_protocol_types
1047 WHERE pcu_protocol_types.pcu_type_id = pcu_types.pcu_type_id), '{}')
1048 AS pcu_protocol_type_ids
1051 --------------------------------------------------------------------------------
1052 CREATE OR REPLACE VIEW view_events AS
1063 CAST(date_part('epoch', events.time) AS bigint) AS time,
1064 COALESCE((SELECT object_ids FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_ids,
1065 COALESCE((SELECT object_types FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_types
1068 CREATE OR REPLACE VIEW view_event_objects AS
1078 CAST(date_part('epoch', events.time) AS bigint) AS time,
1079 event_object.object_id,
1080 event_object.object_type
1081 FROM events LEFT JOIN event_object USING (event_id);
1083 --------------------------------------------------------------------------------
1084 CREATE OR REPLACE VIEW view_persons AS
1093 persons.verification_key,
1094 CAST(date_part('epoch', persons.verification_expires) AS bigint) AS verification_expires,
1099 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
1100 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
1101 peer_person.peer_id,
1102 peer_person.peer_person_id,
1103 COALESCE((SELECT role_ids FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS role_ids,
1104 COALESCE((SELECT roles FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS roles,
1105 COALESCE((SELECT site_ids FROM person_sites WHERE person_sites.person_id = persons.person_id), '{}') AS site_ids,
1106 COALESCE((SELECT key_ids FROM person_keys WHERE person_keys.person_id = persons.person_id), '{}') AS key_ids,
1107 COALESCE((SELECT slice_ids FROM person_slices WHERE person_slices.person_id = persons.person_id), '{}') AS slice_ids,
1108 COALESCE((SELECT person_tag_ids FROM person_tags WHERE person_tags.person_id = persons.person_id), '{}') AS person_tag_ids
1110 LEFT JOIN peer_person USING (person_id);
1112 --------------------------------------------------------------------------------
1113 CREATE OR REPLACE VIEW view_peers AS
1116 COALESCE((SELECT site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS site_ids,
1117 COALESCE((SELECT peer_site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS peer_site_ids,
1118 COALESCE((SELECT person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS person_ids,
1119 COALESCE((SELECT peer_person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS peer_person_ids,
1120 COALESCE((SELECT key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS key_ids,
1121 COALESCE((SELECT peer_key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS peer_key_ids,
1122 COALESCE((SELECT node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS node_ids,
1123 COALESCE((SELECT peer_node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS peer_node_ids,
1124 COALESCE((SELECT slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS slice_ids,
1125 COALESCE((SELECT peer_slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS peer_slice_ids
1128 --------------------------------------------------------------------------------
1129 CREATE OR REPLACE VIEW node_tags AS
1131 array_accum(node_tag_id) AS node_tag_ids
1135 CREATE OR REPLACE VIEW view_node_tags AS
1137 node_tag.node_tag_id,
1140 tag_types.tag_type_id,
1142 tag_types.description,
1144 tag_types.min_role_id,
1147 INNER JOIN tag_types USING (tag_type_id)
1148 INNER JOIN nodes USING (node_id);
1150 CREATE OR REPLACE VIEW view_nodes AS
1165 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
1166 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
1167 CAST(date_part('epoch', nodes.last_contact) AS bigint) AS last_contact,
1169 peer_node.peer_node_id,
1170 COALESCE((SELECT interface_ids FROM node_interfaces
1171 WHERE node_interfaces.node_id = nodes.node_id), '{}')
1173 COALESCE((SELECT nodegroup_ids FROM node_nodegroups
1174 WHERE node_nodegroups.node_id = nodes.node_id), '{}')
1176 COALESCE((SELECT slice_ids FROM node_slices
1177 WHERE node_slices.node_id = nodes.node_id), '{}')
1179 COALESCE((SELECT slice_ids_whitelist FROM node_slices_whitelist
1180 WHERE node_slices_whitelist.node_id = nodes.node_id), '{}')
1181 AS slice_ids_whitelist,
1182 COALESCE((SELECT pcu_ids FROM node_pcus
1183 WHERE node_pcus.node_id = nodes.node_id), '{}')
1185 COALESCE((SELECT ports FROM node_pcus
1186 WHERE node_pcus.node_id = nodes.node_id), '{}')
1188 COALESCE((SELECT conf_file_ids FROM node_conf_files
1189 WHERE node_conf_files.node_id = nodes.node_id), '{}')
1191 COALESCE((SELECT node_tag_ids FROM node_tags
1192 WHERE node_tags.node_id = nodes.node_id), '{}')
1194 node_session.session_id AS session
1196 LEFT JOIN peer_node USING (node_id)
1197 LEFT JOIN node_session USING (node_id);
1199 --------------------------------------------------------------------------------
1200 CREATE OR REPLACE VIEW view_nodegroups AS
1204 COALESCE((SELECT conf_file_ids FROM nodegroup_conf_files
1205 WHERE nodegroup_conf_files.nodegroup_id = nodegroups.nodegroup_id), '{}')
1207 COALESCE((SELECT node_ids FROM nodegroup_nodes
1208 WHERE nodegroup_nodes.nodegroup_id = nodegroups.nodegroup_id), '{}')
1210 FROM nodegroups INNER JOIN tag_types USING (tag_type_id);
1212 --------------------------------------------------------------------------------
1213 CREATE OR REPLACE VIEW view_conf_files AS
1216 COALESCE((SELECT node_ids FROM conf_file_nodes
1217 WHERE conf_file_nodes.conf_file_id = conf_files.conf_file_id), '{}')
1219 COALESCE((SELECT nodegroup_ids FROM conf_file_nodegroups
1220 WHERE conf_file_nodegroups.conf_file_id = conf_files.conf_file_id), '{}')
1224 --------------------------------------------------------------------------------
1225 CREATE OR REPLACE VIEW view_pcus AS
1228 COALESCE((SELECT node_ids FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS node_ids,
1229 COALESCE((SELECT ports FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS ports
1232 --------------------------------------------------------------------------------
1233 CREATE OR REPLACE VIEW view_sites AS
1238 sites.abbreviated_name,
1247 sites.ext_consortium_id,
1248 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
1249 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
1251 peer_site.peer_site_id,
1252 COALESCE((SELECT person_ids FROM site_persons WHERE site_persons.site_id = sites.site_id), '{}') AS person_ids,
1253 COALESCE((SELECT node_ids FROM site_nodes WHERE site_nodes.site_id = sites.site_id), '{}') AS node_ids,
1254 COALESCE((SELECT address_ids FROM site_addresses WHERE site_addresses.site_id = sites.site_id), '{}') AS address_ids,
1255 COALESCE((SELECT slice_ids FROM site_slices WHERE site_slices.site_id = sites.site_id), '{}') AS slice_ids,
1256 COALESCE((SELECT pcu_ids FROM site_pcus WHERE site_pcus.site_id = sites.site_id), '{}') AS pcu_ids,
1257 COALESCE((SELECT site_tag_ids FROM site_tags WHERE site_tags.site_id = sites.site_id), '{}') AS site_tag_ids
1259 LEFT JOIN peer_site USING (site_id);
1261 --------------------------------------------------------------------------------
1262 CREATE OR REPLACE VIEW view_addresses AS
1265 COALESCE((SELECT address_type_ids FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_type_ids,
1266 COALESCE((SELECT address_types FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_types
1269 --------------------------------------------------------------------------------
1270 CREATE OR REPLACE VIEW view_keys AS
1273 person_key.person_id,
1275 peer_key.peer_key_id
1277 LEFT JOIN person_key USING (key_id)
1278 LEFT JOIN peer_key USING (key_id);
1280 --------------------------------------------------------------------------------
1281 CREATE OR REPLACE VIEW slice_tags AS
1283 array_accum(slice_tag_id) AS slice_tag_ids
1287 CREATE OR REPLACE VIEW view_slices AS
1292 slices.instantiation,
1296 slices.creator_person_id,
1298 CAST(date_part('epoch', slices.created) AS bigint) AS created,
1299 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
1301 peer_slice.peer_slice_id,
1302 COALESCE((SELECT node_ids FROM slice_nodes WHERE slice_nodes.slice_id = slices.slice_id), '{}') AS node_ids,
1303 COALESCE((SELECT person_ids FROM slice_persons WHERE slice_persons.slice_id = slices.slice_id), '{}') AS person_ids,
1304 COALESCE((SELECT slice_tag_ids FROM slice_tags WHERE slice_tags.slice_id = slices.slice_id), '{}') AS slice_tag_ids
1306 LEFT JOIN peer_slice USING (slice_id);
1308 CREATE OR REPLACE VIEW view_slice_tags AS
1310 slice_tag.slice_tag_id,
1313 slice_tag.nodegroup_id,
1314 tag_types.tag_type_id,
1316 tag_types.description,
1318 tag_types.min_role_id,
1322 INNER JOIN tag_types USING (tag_type_id)
1323 INNER JOIN slices USING (slice_id);
1325 --------------------------------------------------------------------------------
1326 CREATE OR REPLACE VIEW view_sessions AS
1328 sessions.session_id,
1329 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
1330 person_session.person_id,
1331 node_session.node_id
1333 LEFT JOIN person_session USING (session_id)
1334 LEFT JOIN node_session USING (session_id);
1336 --------------------------------------------------------------------------------
1337 -- Built-in maintenance account and default site
1338 --------------------------------------------------------------------------------
1340 INSERT INTO persons (first_name, last_name, email, password, enabled)
1341 VALUES ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
1343 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
1344 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
1345 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
1346 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
1348 INSERT INTO sites (login_base, name, abbreviated_name, max_slices)
1349 VALUES ('pl', 'PlanetLab Central', 'PLC', 100);