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 --------------------------------------------------------------------------------
19 --------------------------------------------------------------------------------
22 CREATE TABLE plc_db_version (
23 version integer NOT NULL,
24 subversion integer NOT NULL DEFAULT 0
27 INSERT INTO plc_db_version (version, subversion) VALUES (5, 0);
29 --------------------------------------------------------------------------------
30 -- Aggregates and store procedures
31 --------------------------------------------------------------------------------
33 -- Like MySQL GROUP_CONCAT(), this function aggregates values into a
35 CREATE AGGREGATE array_accum (
37 basetype = anyelement,
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
56 password text NOT NULL DEFAULT 'nopass', -- Password (md5crypted)
57 verification_key text, -- Reset password key
58 verification_expires timestamp without time zone,
61 title text, -- Honorific
62 phone text, -- Telephone number
63 url text, -- Home page
64 bio text, -- Biography
67 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
68 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
70 CREATE INDEX persons_email_idx ON persons (email);
72 --------------------------------------------------------------------------------
74 --------------------------------------------------------------------------------
79 site_id serial PRIMARY KEY, -- Site identifier
80 login_base text NOT NULL, -- Site slice prefix
81 name text NOT NULL, -- Site name
82 abbreviated_name text NOT NULL, -- Site abbreviated name
83 enabled boolean NOT NULL Default true, -- Is this site enabled
84 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
85 is_public boolean NOT NULL DEFAULT true, -- Shows up in public lists
86 max_slices integer NOT NULL DEFAULT 0, -- Maximum number of slices
87 max_slivers integer NOT NULL DEFAULT 1000, -- Maximum number of instantiated slivers
93 ext_consortium_id integer, -- external consortium id
96 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
97 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
99 CREATE INDEX sites_login_base_idx ON sites (login_base);
101 -- Account site membership
102 CREATE TABLE person_site (
103 person_id integer REFERENCES persons NOT NULL, -- Account identifier
104 site_id integer REFERENCES sites NOT NULL, -- Site identifier
105 is_primary boolean NOT NULL DEFAULT false, -- Is the primary site for this account
106 PRIMARY KEY (person_id, site_id)
108 CREATE INDEX person_site_person_id_idx ON person_site (person_id);
109 CREATE INDEX person_site_site_id_idx ON person_site (site_id);
111 -- Ordered by primary site first
112 CREATE OR REPLACE VIEW person_site_ordered AS
113 SELECT person_id, site_id
115 ORDER BY is_primary DESC;
117 -- Sites that each person is a member of
118 CREATE OR REPLACE VIEW person_sites AS
120 array_accum(site_id) AS site_ids
121 FROM person_site_ordered
124 -- Accounts at each site
125 CREATE OR REPLACE VIEW site_persons AS
127 array_accum(person_id) AS person_ids
131 --------------------------------------------------------------------------------
133 --------------------------------------------------------------------------------
135 CREATE TABLE address_types (
136 address_type_id serial PRIMARY KEY, -- Address type identifier
137 name text UNIQUE NOT NULL, -- Address type
138 description text -- Address type description
141 -- 'Billing' Used to be 'Site'
142 INSERT INTO address_types (name) VALUES ('Personal'), ('Shipping'), ('Billing');
145 CREATE TABLE addresses (
146 address_id serial PRIMARY KEY, -- Address identifier
147 line1 text NOT NULL, -- Address line 1
148 line2 text, -- Address line 2
149 line3 text, -- Address line 3
150 city text NOT NULL, -- City
151 state text NOT NULL, -- State or province
152 postalcode text NOT NULL, -- Postal code
153 country text NOT NULL -- Country
156 -- Each mailing address can be one of several types
157 CREATE TABLE address_address_type (
158 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
159 address_type_id integer REFERENCES address_types NOT NULL, -- Address type
160 PRIMARY KEY (address_id, address_type_id)
162 CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
163 CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);
165 CREATE OR REPLACE VIEW address_address_types AS
167 array_accum(address_type_id) AS address_type_ids,
168 array_accum(address_types.name) AS address_types
169 FROM address_address_type
170 LEFT JOIN address_types USING (address_type_id)
173 CREATE TABLE site_address (
174 site_id integer REFERENCES sites NOT NULL, -- Site identifier
175 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
176 PRIMARY KEY (site_id, address_id)
178 CREATE INDEX site_address_site_id_idx ON site_address (site_id);
179 CREATE INDEX site_address_address_id_idx ON site_address (address_id);
181 CREATE OR REPLACE VIEW site_addresses AS
183 array_accum(address_id) AS address_ids
187 --------------------------------------------------------------------------------
188 -- Authentication Keys
189 --------------------------------------------------------------------------------
192 CREATE TABLE key_types (
193 key_type text PRIMARY KEY -- Key type
195 INSERT INTO key_types (key_type) VALUES ('ssh');
197 -- Authentication keys
199 key_id serial PRIMARY KEY, -- Key identifier
200 key_type text REFERENCES key_types NOT NULL, -- Key type
201 key text NOT NULL, -- Key material
202 is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
205 -- Account authentication key(s)
206 CREATE TABLE person_key (
207 key_id integer REFERENCES keys PRIMARY KEY, -- Key identifier
208 person_id integer REFERENCES persons NOT NULL -- Account identifier
210 CREATE INDEX person_key_person_id_idx ON person_key (person_id);
212 CREATE OR REPLACE VIEW person_keys AS
214 array_accum(key_id) AS key_ids
218 --------------------------------------------------------------------------------
220 --------------------------------------------------------------------------------
222 -- Valid account roles
224 role_id integer PRIMARY KEY, -- Role identifier
225 name text UNIQUE NOT NULL -- Role symbolic name
227 INSERT INTO roles (role_id, name) VALUES (10, 'admin'), (20, 'pi'), (30, 'user'), (40, 'tech');
229 CREATE TABLE person_role (
230 person_id integer REFERENCES persons NOT NULL, -- Account identifier
231 role_id integer REFERENCES roles NOT NULL, -- Role identifier
232 PRIMARY KEY (person_id, role_id)
234 CREATE INDEX person_role_person_id_idx ON person_role (person_id);
237 CREATE OR REPLACE VIEW person_roles AS
239 array_accum(role_id) AS role_ids,
240 array_accum(roles.name) AS roles
242 LEFT JOIN roles USING (role_id)
245 --------------------------------------------------------------------------------
247 --------------------------------------------------------------------------------
249 -- Valid node boot states
250 CREATE TABLE boot_states (
251 boot_state text PRIMARY KEY
253 INSERT INTO boot_states (boot_state)
254 VALUES ('boot'), ('dbg'), ('diag'), ('disable'), ('inst'), ('rins'), ('new');
259 node_id serial PRIMARY KEY, -- Node identifier
260 hostname text NOT NULL, -- Node hostname
261 site_id integer REFERENCES sites NOT NULL, -- At which site
263 boot_state text REFERENCES boot_states NOT NULL -- Node boot state
265 deleted boolean NOT NULL DEFAULT false, -- Is deleted
268 model text, -- Hardware make and model
269 boot_nonce text, -- Random nonce updated by Boot Manager
270 version text, -- Boot CD version string updated by Boot Manager
271 ssh_rsa_key text, -- SSH host key updated by Boot Manager
272 key text, -- Node key generated when boot file is downloaded
275 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
276 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
277 last_contact timestamp without time zone
279 CREATE INDEX nodes_hostname_idx ON nodes (hostname);
280 CREATE INDEX nodes_site_id_idx ON nodes (site_id);
282 -- Nodes at each site
283 CREATE OR REPLACE VIEW site_nodes AS
285 array_accum(node_id) AS node_ids
287 WHERE deleted IS false
290 --------------------------------------------------------------------------------
292 --------------------------------------------------------------------------------
293 CREATE TABLE node_tag_types (
295 node_tag_type_id serial PRIMARY KEY, -- ID
296 tagname text UNIQUE NOT NULL, -- Tag Name
297 description text, -- Optional Description
298 category text NOT NULL DEFAULT 'general', -- Free text for grouping tags together
299 min_role_id integer REFERENCES roles DEFAULT 10 -- set minimal role required
302 CREATE TABLE node_tag (
303 node_tag_id serial PRIMARY KEY, -- ID
304 node_id integer REFERENCES nodes NOT NULL, -- node id
305 node_tag_type_id integer REFERENCES node_tag_types, -- tag type id
306 tagvalue text -- value attached
309 CREATE OR REPLACE VIEW node_tags AS
311 array_accum(node_tag_id) AS tag_ids
315 CREATE OR REPLACE VIEW view_node_tags AS
317 node_tag.node_tag_id,
320 node_tag_types.node_tag_type_id,
321 node_tag_types.tagname,
322 node_tag_types.description,
323 node_tag_types.category,
324 node_tag_types.min_role_id,
327 INNER JOIN node_tag_types USING (node_tag_type_id)
328 INNER JOIN nodes USING (node_id);
330 --------------------------------------------------------------------------------
332 --------------------------------------------------------------------------------
335 CREATE TABLE nodegroups (
336 nodegroup_id serial PRIMARY KEY, -- Group identifier
337 groupname text UNIQUE NOT NULL, -- Group name
338 node_tag_type_id integer REFERENCES node_tag_types, -- node is in nodegroup if it has this tag defined
339 tagvalue text NOT NULL -- with this value attached
342 -- xxx - first rough implem
343 CREATE OR REPLACE VIEW nodegroup_node AS
344 SELECT nodegroup_id, node_id
347 USING (node_tag_type_id)
349 USING (node_tag_type_id,tagvalue);
351 CREATE OR REPLACE VIEW nodegroup_nodes AS
353 array_accum(node_id) AS node_ids
355 GROUP BY nodegroup_id;
357 -- Node groups that each node is a member of
358 CREATE OR REPLACE VIEW node_nodegroups AS
360 array_accum(nodegroup_id) AS nodegroup_ids
364 --------------------------------------------------------------------------------
365 -- Node configuration files
366 --------------------------------------------------------------------------------
368 CREATE TABLE conf_files (
369 conf_file_id serial PRIMARY KEY, -- Configuration file identifier
370 enabled bool NOT NULL DEFAULT true, -- Configuration file is active
371 source text NOT NULL, -- Relative path on the boot server
372 -- where file can be downloaded
373 dest text NOT NULL, -- Absolute path where file should be installed
374 file_permissions text NOT NULL DEFAULT '0644', -- chmod(1) permissions
375 file_owner text NOT NULL DEFAULT 'root', -- chown(1) owner
376 file_group text NOT NULL DEFAULT 'root', -- chgrp(1) owner
377 preinstall_cmd text, -- Shell command to execute prior to installing
378 postinstall_cmd text, -- Shell command to execute after installing
379 error_cmd text, -- Shell command to execute if any error occurs
380 ignore_cmd_errors bool NOT NULL DEFAULT false, -- Install file anyway even if an error occurs
381 always_update bool NOT NULL DEFAULT false -- Always attempt to install file even if unchanged
384 CREATE TABLE conf_file_node (
385 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
386 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
387 PRIMARY KEY (conf_file_id, node_id)
389 CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
390 CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
392 -- Nodes linked to each configuration file
393 CREATE OR REPLACE VIEW conf_file_nodes AS
395 array_accum(node_id) AS node_ids
397 GROUP BY conf_file_id;
399 -- Configuration files linked to each node
400 CREATE OR REPLACE VIEW node_conf_files AS
402 array_accum(conf_file_id) AS conf_file_ids
406 CREATE TABLE conf_file_nodegroup (
407 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
408 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Node group identifier
409 PRIMARY KEY (conf_file_id, nodegroup_id)
411 CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
412 CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
414 -- Node groups linked to each configuration file
415 CREATE OR REPLACE VIEW conf_file_nodegroups AS
417 array_accum(nodegroup_id) AS nodegroup_ids
418 FROM conf_file_nodegroup
419 GROUP BY conf_file_id;
421 -- Configuration files linked to each node group
422 CREATE OR REPLACE VIEW nodegroup_conf_files AS
424 array_accum(conf_file_id) AS conf_file_ids
425 FROM conf_file_nodegroup
426 GROUP BY nodegroup_id;
428 --------------------------------------------------------------------------------
429 -- Node network interfaces
430 --------------------------------------------------------------------------------
432 -- Valid network addressing schemes
433 CREATE TABLE network_types (
434 type text PRIMARY KEY -- Addressing scheme
436 INSERT INTO network_types (type) VALUES ('ipv4');
438 -- Valid network configuration methods
439 CREATE TABLE network_methods (
440 method text PRIMARY KEY -- Configuration method
442 INSERT INTO network_methods (method) VALUES
443 ('static'), ('dhcp'), ('proxy'), ('tap'), ('ipmi'), ('unknown');
445 -- Node network interfaces
446 CREATE TABLE interfaces (
448 interface_id serial PRIMARY KEY, -- Network interface identifier
449 node_id integer REFERENCES nodes NOT NULL, -- Which node
450 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
451 type text REFERENCES network_types NOT NULL, -- Addressing scheme
452 method text REFERENCES network_methods NOT NULL, -- Configuration method
454 -- Optional, depending on type and method
455 ip text, -- IP address
456 mac text, -- MAC address
457 gateway text, -- Default gateway address
458 network text, -- Network address
459 broadcast text, -- Network broadcast address
460 netmask text, -- Network mask
461 dns1 text, -- Primary DNS server
462 dns2 text, -- Secondary DNS server
463 bwlimit integer, -- Bandwidth limit in bps
464 hostname text -- Hostname of this interface
466 CREATE INDEX interfaces_node_id_idx ON interfaces (node_id);
468 -- Ordered by primary interface first
469 CREATE OR REPLACE VIEW interfaces_ordered AS
470 SELECT node_id, interface_id
472 ORDER BY is_primary DESC;
474 -- Network interfaces on each node
475 CREATE OR REPLACE VIEW node_interfaces AS
477 array_accum(interface_id) AS interface_ids
478 FROM interfaces_ordered
481 --------------------------------------------------------------------------------
482 -- Interface setting types and interfaces settings
483 --------------------------------------------------------------------------------
485 CREATE TABLE interface_setting_types (
486 interface_setting_type_id serial PRIMARY KEY, -- Setting Type Identifier
487 name text UNIQUE NOT NULL, -- Setting Name
488 description text, -- Optional Description
489 category text NOT NULL DEFAULT 'general', -- Free text for grouping, e.g. Wifi, or whatever
490 min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimal role required
493 CREATE TABLE interface_setting (
494 interface_setting_id serial PRIMARY KEY, -- Interface Setting Identifier
495 interface_id integer REFERENCES interfaces NOT NULL,-- the interface this applies to
496 interface_setting_type_id integer
497 REFERENCES interface_setting_types NOT NULL, -- the setting type
498 value text -- value attached
501 CREATE OR REPLACE VIEW interface_settings AS
503 array_accum(interface_setting_id) AS setting_ids
504 FROM interface_setting
505 GROUP BY interface_id;
507 CREATE OR REPLACE VIEW view_interface_settings AS
509 interface_setting.interface_setting_id,
510 interface_setting.interface_id,
511 interface_setting_types.interface_setting_type_id,
512 interface_setting_types.name,
513 interface_setting_types.description,
514 interface_setting_types.category,
515 interface_setting_types.min_role_id,
516 interface_setting.value
517 FROM interface_setting
518 INNER JOIN interface_setting_types USING (interface_setting_type_id);
520 CREATE OR REPLACE VIEW view_interfaces AS
522 interfaces.interface_id,
524 interfaces.is_primary,
531 interfaces.broadcast,
537 COALESCE((SELECT setting_ids FROM interface_settings WHERE interface_settings.interface_id = interfaces.interface_id), '{}') AS setting_ids
540 --------------------------------------------------------------------------------
541 -- Power control units (PCUs)
542 --------------------------------------------------------------------------------
546 pcu_id serial PRIMARY KEY, -- PCU identifier
547 site_id integer REFERENCES sites NOT NULL, -- Site identifier
548 hostname text, -- Hostname, not necessarily unique
549 -- (multiple logical sites could use the same PCU)
550 ip text NOT NULL, -- IP, not necessarily unique
553 protocol text, -- Protocol, e.g. ssh or https or telnet
554 username text, -- Username, if applicable
555 "password" text, -- Password, if applicable
556 model text, -- Model, e.g. BayTech or iPal
557 notes text -- Random notes
559 CREATE INDEX pcus_site_id_idx ON pcus (site_id);
561 CREATE OR REPLACE VIEW site_pcus AS
563 array_accum(pcu_id) AS pcu_ids
567 CREATE TABLE pcu_node (
568 pcu_id integer REFERENCES pcus NOT NULL, -- PCU identifier
569 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
570 port integer NOT NULL, -- Port number
571 PRIMARY KEY (pcu_id, node_id), -- The same node cannot be controlled by different ports
572 UNIQUE (pcu_id, port) -- The same port cannot control multiple nodes
574 CREATE INDEX pcu_node_pcu_id_idx ON pcu_node (pcu_id);
575 CREATE INDEX pcu_node_node_id_idx ON pcu_node (node_id);
577 CREATE OR REPLACE VIEW node_pcus AS
579 array_accum(pcu_id) AS pcu_ids,
580 array_accum(port) AS ports
584 CREATE OR REPLACE VIEW pcu_nodes AS
586 array_accum(node_id) AS node_ids,
587 array_accum(port) AS ports
591 --------------------------------------------------------------------------------
593 --------------------------------------------------------------------------------
595 CREATE TABLE slice_instantiations (
596 instantiation text PRIMARY KEY
598 INSERT INTO slice_instantiations (instantiation) VALUES
599 ('not-instantiated'), -- Placeholder slice
600 ('plc-instantiated'), -- Instantiated by Node Manager
601 ('delegated'), -- Manually instantiated
602 ('nm-controller'); -- NM Controller
605 CREATE TABLE slices (
606 slice_id serial PRIMARY KEY, -- Slice identifier
607 site_id integer REFERENCES sites NOT NULL, -- Site identifier
609 name text NOT NULL, -- Slice name
610 instantiation text REFERENCES slice_instantiations -- Slice state, e.g. plc-instantiated
611 NOT NULL DEFAULT 'plc-instantiated',
612 url text, -- Project URL
613 description text, -- Project description
615 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
617 creator_person_id integer REFERENCES persons, -- Creator
618 created timestamp without time zone NOT NULL -- Creation date
619 DEFAULT CURRENT_TIMESTAMP,
620 expires timestamp without time zone NOT NULL -- Expiration date
621 DEFAULT CURRENT_TIMESTAMP + '2 weeks',
623 is_deleted boolean NOT NULL DEFAULT false
625 CREATE INDEX slices_site_id_idx ON slices (site_id);
626 CREATE INDEX slices_name_idx ON slices (name);
629 CREATE TABLE slice_node (
630 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
631 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
632 PRIMARY KEY (slice_id, node_id)
634 CREATE INDEX slice_node_slice_id_idx ON slice_node (slice_id);
635 CREATE INDEX slice_node_node_id_idx ON slice_node (node_id);
637 -- Synonym for slice_node
638 CREATE OR REPLACE VIEW slivers AS
639 SELECT * FROM slice_node;
641 -- Nodes in each slice
642 CREATE OR REPLACE VIEW slice_nodes AS
644 array_accum(node_id) AS node_ids
648 -- Slices on each node
649 CREATE OR REPLACE VIEW node_slices AS
651 array_accum(slice_id) AS slice_ids
655 -- Slices at each site
656 CREATE OR REPLACE VIEW site_slices AS
658 array_accum(slice_id) AS slice_ids
660 WHERE is_deleted is false
664 CREATE TABLE slice_person (
665 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
666 person_id integer REFERENCES persons NOT NULL, -- Account identifier
667 PRIMARY KEY (slice_id, person_id)
669 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
670 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
672 -- Members of the slice
673 CREATE OR REPLACE VIEW slice_persons AS
675 array_accum(person_id) AS person_ids
679 -- Slices of which each person is a member
680 CREATE OR REPLACE VIEW person_slices AS
682 array_accum(slice_id) AS slice_ids
686 --------------------------------------------------------------------------------
688 --------------------------------------------------------------------------------
689 -- slice whitelist on nodes
690 CREATE TABLE node_slice_whitelist (
691 node_id integer REFERENCES nodes NOT NULL, -- Node id of whitelist
692 slice_id integer REFERENCES slices NOT NULL, -- Slice id thats allowd on this node
693 PRIMARY KEY (node_id, slice_id)
695 CREATE INDEX node_slice_whitelist_node_id_idx ON node_slice_whitelist (node_id);
696 CREATE INDEX node_slice_whitelist_slice_id_idx ON node_slice_whitelist (slice_id);
698 -- Slices on each node
699 CREATE OR REPLACE VIEW node_slices_whitelist AS
701 array_accum(slice_id) AS slice_ids_whitelist
702 FROM node_slice_whitelist
705 --------------------------------------------------------------------------------
707 --------------------------------------------------------------------------------
709 -- Slice attribute types
710 CREATE TABLE slice_attribute_types (
711 attribute_type_id serial PRIMARY KEY, -- Attribute type identifier
712 name text UNIQUE NOT NULL, -- Attribute name
713 description text, -- Attribute description
714 min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can
715 -- set or change this attribute
718 -- Slice/sliver attributes
719 CREATE TABLE slice_attribute (
720 slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
721 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
722 node_id integer REFERENCES nodes, -- Sliver attribute if set
723 nodegroup_id integer REFERENCES nodegroups, -- Node group attribute if set
724 attribute_type_id integer -- Attribute type identifier
725 REFERENCES slice_attribute_types NOT NULL,
728 CREATE INDEX slice_attribute_slice_id_idx ON slice_attribute (slice_id);
729 CREATE INDEX slice_attribute_node_id_idx ON slice_attribute (node_id);
730 CREATE INDEX slice_attribute_nodegroup_id_idx ON slice_attribute (nodegroup_id);
732 CREATE OR REPLACE VIEW slice_attributes AS
734 array_accum(slice_attribute_id) AS slice_attribute_ids
738 --------------------------------------------------------------------------------
740 --------------------------------------------------------------------------------
743 CREATE TABLE initscripts (
744 initscript_id serial PRIMARY KEY, -- Initscript identifier
745 name text NOT NULL, -- Initscript name
746 enabled bool NOT NULL DEFAULT true, -- Initscript is active
747 script text NOT NULL, -- Initscript body
750 CREATE INDEX initscripts_name_idx ON initscripts (name);
753 --------------------------------------------------------------------------------
755 --------------------------------------------------------------------------------
759 peer_id serial PRIMARY KEY, -- Peer identifier
760 peername text NOT NULL, -- Peer name
761 peer_url text NOT NULL, -- (HTTPS) URL of the peer PLCAPI interface
762 cacert text, -- (SSL) Public certificate of peer API server
763 key text, -- (GPG) Public key used for authentication
764 deleted boolean NOT NULL DEFAULT false
766 CREATE INDEX peers_peername_idx ON peers (peername) WHERE deleted IS false;
768 -- Objects at each peer
769 CREATE TABLE peer_site (
770 site_id integer REFERENCES sites PRIMARY KEY, -- Local site identifier
771 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
772 peer_site_id integer NOT NULL, -- Foreign site identifier at peer
773 UNIQUE (peer_id, peer_site_id) -- The same foreign site should not be cached twice
775 CREATE INDEX peer_site_peer_id_idx ON peers (peer_id);
777 CREATE OR REPLACE VIEW peer_sites AS
779 array_accum(site_id) AS site_ids,
780 array_accum(peer_site_id) AS peer_site_ids
784 CREATE TABLE peer_person (
785 person_id integer REFERENCES persons PRIMARY KEY, -- Local user identifier
786 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
787 peer_person_id integer NOT NULL, -- Foreign user identifier at peer
788 UNIQUE (peer_id, peer_person_id) -- The same foreign user should not be cached twice
790 CREATE INDEX peer_person_peer_id_idx ON peer_person (peer_id);
792 CREATE OR REPLACE VIEW peer_persons AS
794 array_accum(person_id) AS person_ids,
795 array_accum(peer_person_id) AS peer_person_ids
799 CREATE TABLE peer_key (
800 key_id integer REFERENCES keys PRIMARY KEY, -- Local key identifier
801 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
802 peer_key_id integer NOT NULL, -- Foreign key identifier at peer
803 UNIQUE (peer_id, peer_key_id) -- The same foreign key should not be cached twice
805 CREATE INDEX peer_key_peer_id_idx ON peer_key (peer_id);
807 CREATE OR REPLACE VIEW peer_keys AS
809 array_accum(key_id) AS key_ids,
810 array_accum(peer_key_id) AS peer_key_ids
814 CREATE TABLE peer_node (
815 node_id integer REFERENCES nodes PRIMARY KEY, -- Local node identifier
816 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
817 peer_node_id integer NOT NULL, -- Foreign node identifier
818 UNIQUE (peer_id, peer_node_id) -- The same foreign node should not be cached twice
820 CREATE INDEX peer_node_peer_id_idx ON peer_node (peer_id);
822 CREATE OR REPLACE VIEW peer_nodes AS
824 array_accum(node_id) AS node_ids,
825 array_accum(peer_node_id) AS peer_node_ids
829 CREATE TABLE peer_slice (
830 slice_id integer REFERENCES slices PRIMARY KEY, -- Local slice identifier
831 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
832 peer_slice_id integer NOT NULL, -- Slice identifier at peer
833 UNIQUE (peer_id, peer_slice_id) -- The same foreign slice should not be cached twice
835 CREATE INDEX peer_slice_peer_id_idx ON peer_slice (peer_id);
837 CREATE OR REPLACE VIEW peer_slices AS
839 array_accum(slice_id) AS slice_ids,
840 array_accum(peer_slice_id) AS peer_slice_ids
844 --------------------------------------------------------------------------------
845 -- Authenticated sessions
846 --------------------------------------------------------------------------------
848 -- Authenticated sessions
849 CREATE TABLE sessions (
850 session_id text PRIMARY KEY, -- Session identifier
851 expires timestamp without time zone
854 -- People can have multiple sessions
855 CREATE TABLE person_session (
856 person_id integer REFERENCES persons NOT NULL, -- Account identifier
857 session_id text REFERENCES sessions NOT NULL, -- Session identifier
858 PRIMARY KEY (person_id, session_id),
859 UNIQUE (session_id) -- Sessions are unique
861 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
863 -- Nodes can have only one session
864 CREATE TABLE node_session (
865 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
866 session_id text REFERENCES sessions NOT NULL, -- Session identifier
867 UNIQUE (node_id), -- Nodes can have only one session
868 UNIQUE (session_id) -- Sessions are unique
871 -------------------------------------------------------------------------------
873 ------------------------------------------------------------------------------
874 CREATE TABLE pcu_types (
875 pcu_type_id serial PRIMARY KEY,
876 model text NOT NULL , -- PCU model name
877 name text -- Full PCU model name
879 CREATE INDEX pcu_types_model_idx ON pcu_types (model);
881 CREATE TABLE pcu_protocol_type (
882 pcu_protocol_type_id serial PRIMARY KEY,
883 pcu_type_id integer REFERENCES pcu_types NOT NULL, -- PCU type identifier
884 port integer NOT NULL, -- PCU port
885 protocol text NOT NULL, -- Protocol
886 supported boolean NOT NULL DEFAULT True -- Does PLC support
888 CREATE INDEX pcu_protocol_type_pcu_type_id ON pcu_protocol_type (pcu_type_id);
891 CREATE OR REPLACE VIEW pcu_protocol_types AS
893 array_accum(pcu_protocol_type_id) as pcu_protocol_type_ids
894 FROM pcu_protocol_type
895 GROUP BY pcu_type_id;
897 --------------------------------------------------------------------------------
899 --------------------------------------------------------------------------------
901 CREATE TABLE messages (
902 message_id text PRIMARY KEY, -- Message name
903 subject text, -- Message summary
904 template text, -- Message template
905 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
908 --------------------------------------------------------------------------------
910 --------------------------------------------------------------------------------
913 CREATE TABLE events (
914 event_id serial PRIMARY KEY, -- Event identifier
915 person_id integer REFERENCES persons, -- Person responsible for event, if any
916 node_id integer REFERENCES nodes, -- Node responsible for event, if any
917 auth_type text, -- Type of auth used. i.e. AuthMethod
918 fault_code integer NOT NULL DEFAULT 0, -- Did this event result in error
919 call_name text NOT NULL, -- Call responsible for this event
920 call text NOT NULL, -- Call responsible for this event, including parameters
921 message text, -- High level description of this event
922 runtime float DEFAULT 0, -- Event run time
923 time timestamp without time zone NOT NULL -- Event timestamp
924 DEFAULT CURRENT_TIMESTAMP
927 -- Database object(s) that may have been affected by a particular event
928 CREATE TABLE event_object (
929 event_id integer REFERENCES events NOT NULL, -- Event identifier
930 object_id integer NOT NULL, -- Object identifier
931 object_type text NOT NULL Default 'Unknown' -- What type of object is this event affecting
933 CREATE INDEX event_object_event_id_idx ON event_object (event_id);
934 CREATE INDEX event_object_object_id_idx ON event_object (object_id);
935 CREATE INDEX event_object_object_type_idx ON event_object (object_type);
937 CREATE OR REPLACE VIEW event_objects AS
939 array_accum(object_id) AS object_ids,
940 array_accum(object_type) AS object_types
944 --------------------------------------------------------------------------------
946 --------------------------------------------------------------------------------
947 CREATE OR REPLACE VIEW view_pcu_types AS
949 pcu_types.pcu_type_id,
952 COALESCE((SELECT pcu_protocol_type_ids FROM pcu_protocol_types
953 WHERE pcu_protocol_types.pcu_type_id = pcu_types.pcu_type_id), '{}')
954 AS pcu_protocol_type_ids
957 CREATE OR REPLACE VIEW view_events AS
968 CAST(date_part('epoch', events.time) AS bigint) AS time,
969 COALESCE((SELECT object_ids FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_ids,
970 COALESCE((SELECT object_types FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_types
973 CREATE OR REPLACE VIEW view_event_objects AS
983 CAST(date_part('epoch', events.time) AS bigint) AS time,
984 event_object.object_id,
985 event_object.object_type
986 FROM events LEFT JOIN event_object USING (event_id);
988 CREATE OR REPLACE VIEW view_persons AS
997 persons.verification_key,
998 CAST(date_part('epoch', persons.verification_expires) AS bigint) AS verification_expires,
1003 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
1004 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
1005 peer_person.peer_id,
1006 peer_person.peer_person_id,
1007 COALESCE((SELECT role_ids FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS role_ids,
1008 COALESCE((SELECT roles FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS roles,
1009 COALESCE((SELECT site_ids FROM person_sites WHERE person_sites.person_id = persons.person_id), '{}') AS site_ids,
1010 COALESCE((SELECT key_ids FROM person_keys WHERE person_keys.person_id = persons.person_id), '{}') AS key_ids,
1011 COALESCE((SELECT slice_ids FROM person_slices WHERE person_slices.person_id = persons.person_id), '{}') AS slice_ids
1013 LEFT JOIN peer_person USING (person_id);
1015 CREATE OR REPLACE VIEW view_peers AS
1018 COALESCE((SELECT site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS site_ids,
1019 COALESCE((SELECT peer_site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS peer_site_ids,
1020 COALESCE((SELECT person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS person_ids,
1021 COALESCE((SELECT peer_person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS peer_person_ids,
1022 COALESCE((SELECT key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS key_ids,
1023 COALESCE((SELECT peer_key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS peer_key_ids,
1024 COALESCE((SELECT node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS node_ids,
1025 COALESCE((SELECT peer_node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS peer_node_ids,
1026 COALESCE((SELECT slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS slice_ids,
1027 COALESCE((SELECT peer_slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS peer_slice_ids
1030 CREATE OR REPLACE VIEW view_nodes AS
1042 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
1043 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
1044 CAST(date_part('epoch', nodes.last_contact) AS bigint) AS last_contact,
1046 peer_node.peer_node_id,
1047 COALESCE((SELECT interface_ids FROM node_interfaces
1048 WHERE node_interfaces.node_id = nodes.node_id), '{}')
1050 COALESCE((SELECT nodegroup_ids FROM node_nodegroups
1051 WHERE node_nodegroups.node_id = nodes.node_id), '{}')
1053 COALESCE((SELECT slice_ids FROM node_slices
1054 WHERE node_slices.node_id = nodes.node_id), '{}')
1056 COALESCE((SELECT slice_ids_whitelist FROM node_slices_whitelist
1057 WHERE node_slices_whitelist.node_id = nodes.node_id), '{}')
1058 AS slice_ids_whitelist,
1059 COALESCE((SELECT pcu_ids FROM node_pcus
1060 WHERE node_pcus.node_id = nodes.node_id), '{}')
1062 COALESCE((SELECT ports FROM node_pcus
1063 WHERE node_pcus.node_id = nodes.node_id), '{}')
1065 COALESCE((SELECT conf_file_ids FROM node_conf_files
1066 WHERE node_conf_files.node_id = nodes.node_id), '{}')
1068 COALESCE((SELECT tag_ids FROM node_tags
1069 WHERE node_tags.node_id = nodes.node_id), '{}')
1071 node_session.session_id AS session
1073 LEFT JOIN peer_node USING (node_id)
1074 LEFT JOIN node_session USING (node_id);
1076 CREATE OR REPLACE VIEW view_nodegroups AS
1079 node_tag_types.tagname,
1080 COALESCE((SELECT conf_file_ids FROM nodegroup_conf_files
1081 WHERE nodegroup_conf_files.nodegroup_id = nodegroups.nodegroup_id), '{}')
1083 COALESCE((SELECT node_ids FROM nodegroup_nodes
1084 WHERE nodegroup_nodes.nodegroup_id = nodegroups.nodegroup_id), '{}')
1086 FROM nodegroups INNER JOIN node_tag_types USING (node_tag_type_id);
1088 CREATE OR REPLACE VIEW view_conf_files AS
1091 COALESCE((SELECT node_ids FROM conf_file_nodes
1092 WHERE conf_file_nodes.conf_file_id = conf_files.conf_file_id), '{}')
1094 COALESCE((SELECT nodegroup_ids FROM conf_file_nodegroups
1095 WHERE conf_file_nodegroups.conf_file_id = conf_files.conf_file_id), '{}')
1099 CREATE OR REPLACE VIEW view_pcus AS
1102 COALESCE((SELECT node_ids FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS node_ids,
1103 COALESCE((SELECT ports FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS ports
1106 CREATE OR REPLACE VIEW view_sites AS
1111 sites.abbreviated_name,
1120 sites.ext_consortium_id,
1121 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
1122 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
1124 peer_site.peer_site_id,
1125 COALESCE((SELECT person_ids FROM site_persons WHERE site_persons.site_id = sites.site_id), '{}') AS person_ids,
1126 COALESCE((SELECT node_ids FROM site_nodes WHERE site_nodes.site_id = sites.site_id), '{}') AS node_ids,
1127 COALESCE((SELECT address_ids FROM site_addresses WHERE site_addresses.site_id = sites.site_id), '{}') AS address_ids,
1128 COALESCE((SELECT slice_ids FROM site_slices WHERE site_slices.site_id = sites.site_id), '{}') AS slice_ids,
1129 COALESCE((SELECT pcu_ids FROM site_pcus WHERE site_pcus.site_id = sites.site_id), '{}') AS pcu_ids
1131 LEFT JOIN peer_site USING (site_id);
1133 CREATE OR REPLACE VIEW view_addresses AS
1136 COALESCE((SELECT address_type_ids FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_type_ids,
1137 COALESCE((SELECT address_types FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_types
1140 CREATE OR REPLACE VIEW view_keys AS
1143 person_key.person_id,
1145 peer_key.peer_key_id
1147 LEFT JOIN person_key USING (key_id)
1148 LEFT JOIN peer_key USING (key_id);
1150 CREATE OR REPLACE VIEW view_slices AS
1155 slices.instantiation,
1159 slices.creator_person_id,
1161 CAST(date_part('epoch', slices.created) AS bigint) AS created,
1162 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
1164 peer_slice.peer_slice_id,
1165 COALESCE((SELECT node_ids FROM slice_nodes WHERE slice_nodes.slice_id = slices.slice_id), '{}') AS node_ids,
1166 COALESCE((SELECT person_ids FROM slice_persons WHERE slice_persons.slice_id = slices.slice_id), '{}') AS person_ids,
1167 COALESCE((SELECT slice_attribute_ids FROM slice_attributes WHERE slice_attributes.slice_id = slices.slice_id), '{}') AS slice_attribute_ids
1169 LEFT JOIN peer_slice USING (slice_id);
1171 CREATE OR REPLACE VIEW view_slice_attributes AS
1173 slice_attribute.slice_attribute_id,
1174 slice_attribute.slice_id,
1175 slice_attribute.node_id,
1176 slice_attribute.nodegroup_id,
1177 slice_attribute_types.attribute_type_id,
1178 slice_attribute_types.name,
1179 slice_attribute_types.description,
1180 slice_attribute_types.min_role_id,
1181 slice_attribute.value
1182 FROM slice_attribute
1183 INNER JOIN slice_attribute_types USING (attribute_type_id);
1185 CREATE OR REPLACE VIEW view_sessions AS
1187 sessions.session_id,
1188 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
1189 person_session.person_id,
1190 node_session.node_id
1192 LEFT JOIN person_session USING (session_id)
1193 LEFT JOIN node_session USING (session_id);
1195 --------------------------------------------------------------------------------
1196 -- Built-in maintenance account and default site
1197 --------------------------------------------------------------------------------
1200 (first_name, last_name, email, password, enabled)
1202 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
1204 INSERT INTO person_role (person_id, role_id)
1205 VALUES (1, 10), (1, 20), (1, 30), (1, 40);
1208 (login_base, name, abbreviated_name, max_slices)
1210 ('pl', 'PlanetLab Central', 'PLC', 100);