2 -- PlanetLab Central database schema
3 -- Version 4, PostgreSQL
5 -- Aaron Klingaman <alk@cs.princeton.edu>
6 -- Reid Moran <rmoran@cs.princeton.edu>
7 -- Mark Huang <mlhuang@cs.princeton.edu>
8 -- Tony Mack <tmack@cs.princeton.edu>
10 -- Copyright (C) 2006 The Trustees of Princeton University
12 -- $Id: planetlab4.sql,v 1.40 2006/11/17 10:43:17 thierry Exp $
15 --------------------------------------------------------------------------------
16 -- Aggregates and store procedures
17 --------------------------------------------------------------------------------
19 -- Like MySQL GROUP_CONCAT(), this function aggregates values into a
21 CREATE AGGREGATE array_accum (
23 basetype = anyelement,
28 --------------------------------------------------------------------------------
30 --------------------------------------------------------------------------------
33 CREATE TABLE plc_db_version (
34 version integer NOT NULL
37 INSERT INTO plc_db_version (version) VALUES (4);
39 --------------------------------------------------------------------------------
41 --------------------------------------------------------------------------------
44 CREATE TABLE persons (
46 person_id serial PRIMARY KEY, -- Account identifier
47 email text NOT NULL, -- E-mail address
48 first_name text NOT NULL, -- First name
49 last_name text NOT NULL, -- Last name
50 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
51 enabled boolean NOT NULL DEFAULT false, -- Has been disabled
54 password text NOT NULL, -- Password (md5crypted)
55 verification_key text, -- Reset password key
56 verification_expires timestamp without time zone,
59 title text, -- Honorific
60 phone text, -- Telephone number
61 url text, -- Home page
62 bio text, -- Biography
65 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
66 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
68 CREATE INDEX persons_email_idx ON persons (email) WHERE deleted IS false;
70 --------------------------------------------------------------------------------
72 --------------------------------------------------------------------------------
77 site_id serial PRIMARY KEY, -- Site identifier
78 login_base text NOT NULL, -- Site slice prefix
79 name text NOT NULL, -- Site name
80 abbreviated_name text NOT NULL, -- Site abbreviated name
81 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
82 is_public boolean NOT NULL DEFAULT true, -- Shows up in public lists
83 max_slices integer NOT NULL DEFAULT 0, -- Maximum number of slices
84 max_slivers integer NOT NULL DEFAULT 1000, -- Maximum number of instantiated slivers
92 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
93 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
95 CREATE INDEX sites_login_base_idx ON sites (login_base) WHERE deleted IS false;
97 -- Account site membership
98 CREATE TABLE person_site (
99 person_id integer REFERENCES persons NOT NULL, -- Account identifier
100 site_id integer REFERENCES sites NOT NULL, -- Site identifier
101 is_primary boolean NOT NULL DEFAULT false, -- Is the primary site for this account
102 PRIMARY KEY (person_id, site_id)
104 CREATE INDEX person_site_person_id_idx ON person_site (person_id);
105 CREATE INDEX person_site_site_id_idx ON person_site (site_id);
107 -- Ordered by primary site first
108 CREATE VIEW person_site_ordered AS
109 SELECT person_id, site_id
111 ORDER BY is_primary DESC;
113 -- Sites that each person is a member of
114 CREATE VIEW person_sites AS
116 array_accum(site_id) AS site_ids
117 FROM person_site_ordered
120 -- Accounts at each site
121 CREATE VIEW site_persons AS
123 array_accum(person_id) AS person_ids
127 --------------------------------------------------------------------------------
129 --------------------------------------------------------------------------------
131 CREATE TABLE address_types (
132 address_type_id serial PRIMARY KEY, -- Address type identifier
133 name text UNIQUE NOT NULL, -- Address type
134 description text -- Address type description
137 INSERT INTO address_types (name) VALUES ('Personal');
138 INSERT INTO address_types (name) VALUES ('Shipping');
139 -- XXX Used to be Site
140 INSERT INTO address_types (name) VALUES ('Billing');
143 CREATE TABLE addresses (
144 address_id serial PRIMARY KEY, -- Address identifier
145 line1 text NOT NULL, -- Address line 1
146 line2 text, -- Address line 2
147 line3 text, -- Address line 3
148 city text NOT NULL, -- City
149 state text NOT NULL, -- State or province
150 postalcode text NOT NULL, -- Postal code
151 country text NOT NULL -- Country
154 -- Each mailing address can be one of several types
155 CREATE TABLE address_address_type (
156 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
157 address_type_id integer REFERENCES address_types NOT NULL, -- Address type
158 PRIMARY KEY (address_id, address_type_id)
160 CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
161 CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);
163 CREATE VIEW address_address_types AS
165 array_accum(address_type_id) AS address_type_ids,
166 array_accum(address_types.name) AS address_types
167 FROM address_address_type
168 LEFT JOIN address_types USING (address_type_id)
171 CREATE TABLE site_address (
172 site_id integer REFERENCES sites NOT NULL, -- Site identifier
173 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
174 PRIMARY KEY (site_id, address_id)
176 CREATE INDEX site_address_site_id_idx ON site_address (site_id);
177 CREATE INDEX site_address_address_id_idx ON site_address (address_id);
179 CREATE VIEW site_addresses AS
181 array_accum(address_id) AS address_ids
185 --------------------------------------------------------------------------------
186 -- Authentication Keys
187 --------------------------------------------------------------------------------
190 CREATE TABLE key_types (
191 key_type text PRIMARY KEY -- Key type
193 INSERT INTO key_types (key_type) VALUES ('ssh');
195 -- Authentication keys
197 key_id serial PRIMARY KEY, -- Key identifier
198 key_type text REFERENCES key_types NOT NULL, -- Key type
199 key text NOT NULL, -- Key material
200 is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
203 -- Account authentication key(s)
204 CREATE TABLE person_key (
205 person_id integer REFERENCES persons NOT NULL, -- Account identifier
206 key_id integer REFERENCES keys NOT NULL, -- Key identifier
207 PRIMARY KEY (person_id, key_id)
209 CREATE INDEX person_key_person_id_idx ON person_key (person_id);
210 CREATE INDEX person_key_key_id_idx ON person_key (key_id);
212 CREATE 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');
228 INSERT INTO roles (role_id, name) VALUES (20, 'pi');
229 INSERT INTO roles (role_id, name) VALUES (30, 'user');
230 INSERT INTO roles (role_id, name) VALUES (40, 'tech');
231 INSERT INTO roles (role_id, name) VALUES (1000, 'node');
232 INSERT INTO roles (role_id, name) VALUES (2000, 'anonymous');
233 -- xxx not sure this us useful yet
234 --INSERT INTO roles (role_id, name) VALUES (3000, 'peer');
236 CREATE TABLE person_role (
237 person_id integer REFERENCES persons NOT NULL, -- Account identifier
238 role_id integer REFERENCES roles NOT NULL, -- Role identifier
239 PRIMARY KEY (person_id, role_id)
241 CREATE INDEX person_role_person_id_idx ON person_role (person_id);
244 CREATE VIEW person_roles AS
246 array_accum(role_id) AS role_ids,
247 array_accum(roles.name) AS roles
249 LEFT JOIN roles USING (role_id)
252 --------------------------------------------------------------------------------
254 --------------------------------------------------------------------------------
256 -- Valid node boot states
257 CREATE TABLE boot_states (
258 boot_state text PRIMARY KEY
260 INSERT INTO boot_states (boot_state) VALUES ('boot');
261 INSERT INTO boot_states (boot_state) VALUES ('dbg');
262 INSERT INTO boot_states (boot_state) VALUES ('inst');
263 INSERT INTO boot_states (boot_state) VALUES ('rins');
264 INSERT INTO boot_states (boot_state) VALUES ('rcnf');
265 INSERT INTO boot_states (boot_state) VALUES ('new');
269 peer_id serial PRIMARY KEY, -- identifier
270 peername text NOT NULL, -- free text
271 peer_url text NOT NULL, -- the url of that peer's API
272 person_id integer REFERENCES persons NOT NULL, -- the account we use for logging in
274 deleted boolean NOT NULL DEFAULT false
281 node_id serial PRIMARY KEY, -- Node identifier
282 hostname text NOT NULL, -- Node hostname
283 site_id integer REFERENCES sites, -- At which site (clause NOT NULL removed for foreign_nodes)
284 boot_state text REFERENCES boot_states NOT NULL DEFAULT 'inst', -- Node boot state
285 deleted boolean NOT NULL DEFAULT false, -- Is deleted
288 model text, -- Hardware make and model
289 boot_nonce text, -- Random nonce updated by Boot Manager
290 version text, -- Boot CD version string updated by Boot Manager
291 -- XXX Should be key_id integer REFERENCES keys
292 ssh_rsa_key text, -- SSH host key updated by Boot Manager
293 key text, -- Node key generated by API when configuration file is downloaded
296 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
297 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
299 CREATE INDEX nodes_hostname_idx ON nodes (hostname) WHERE deleted IS false;
300 CREATE INDEX nodes_site_id_idx ON nodes (site_id) WHERE deleted IS false;
302 -- Nodes at each site
303 CREATE VIEW site_nodes AS
305 array_accum(node_id) AS node_ids
309 -- Nodes - peers relationship
310 CREATE TABLE peer_node (
311 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
312 node_id integer REFERENCES nodes NOT NULL, -- (Local) node identifier
313 PRIMARY KEY (peer_id, node_id),
314 UNIQUE (node_id) -- Nodes can only be at one peer
316 CREATE INDEX peer_node_peer_id_idx ON peer_node (peer_id);
318 -- Nodes at each peer
319 CREATE VIEW peer_nodes AS
321 array_accum(node_id) AS node_ids
325 --------------------------------------------------------------------------------
327 --------------------------------------------------------------------------------
330 CREATE TABLE nodegroups (
331 nodegroup_id serial PRIMARY KEY, -- Group identifier
332 name text UNIQUE NOT NULL, -- Group name
333 description text -- Group description
336 -- Node group membership
337 CREATE TABLE nodegroup_node (
338 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Group identifier
339 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
340 PRIMARY KEY (nodegroup_id, node_id)
342 CREATE INDEX nodegroup_node_nodegroup_id_idx ON nodegroup_node (nodegroup_id);
343 CREATE INDEX nodegroup_node_node_id_idx ON nodegroup_node (node_id);
345 -- Nodes in each node group
346 CREATE VIEW nodegroup_nodes AS
348 array_accum(node_id) AS node_ids
350 GROUP BY nodegroup_id;
352 -- Node groups that each node is a member of
353 CREATE VIEW node_nodegroups AS
355 array_accum(nodegroup_id) AS nodegroup_ids
359 --------------------------------------------------------------------------------
360 -- Node configuration files
361 --------------------------------------------------------------------------------
363 CREATE TABLE conf_files (
364 conf_file_id serial PRIMARY KEY, -- Configuration file identifier
365 enabled bool NOT NULL DEFAULT true, -- Configuration file is active
366 source text NOT NULL, -- Relative path on the boot server where file can be downloaded
367 dest text NOT NULL, -- Absolute path where file should be installed
368 file_permissions text NOT NULL DEFAULT '0644', -- chmod(1) permissions
369 file_owner text NOT NULL DEFAULT 'root', -- chown(1) owner
370 file_group text NOT NULL DEFAULT 'root', -- chgrp(1) owner
371 preinstall_cmd text, -- Shell command to execute prior to installing
372 postinstall_cmd text, -- Shell command to execute after installing
373 error_cmd text, -- Shell command to execute if any error occurs
374 ignore_cmd_errors bool NOT NULL DEFAULT false, -- Install file anyway even if an error occurs
375 always_update bool NOT NULL DEFAULT false -- Always attempt to install file even if unchanged
378 CREATE TABLE conf_file_node (
379 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
380 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
381 PRIMARY KEY (conf_file_id, node_id)
383 CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
384 CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
386 -- Nodes linked to each configuration file
387 CREATE VIEW conf_file_nodes AS
389 array_accum(node_id) AS node_ids
391 GROUP BY conf_file_id;
393 -- Configuration files linked to each node
394 CREATE VIEW node_conf_files AS
396 array_accum(conf_file_id) AS conf_file_ids
400 CREATE TABLE conf_file_nodegroup (
401 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
402 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Node group identifier
403 PRIMARY KEY (conf_file_id, nodegroup_id)
405 CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
406 CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
408 -- Node groups linked to each configuration file
409 CREATE VIEW conf_file_nodegroups AS
411 array_accum(nodegroup_id) AS nodegroup_ids
412 FROM conf_file_nodegroup
413 GROUP BY conf_file_id;
415 -- Configuration files linked to each node group
416 CREATE VIEW nodegroup_conf_files AS
418 array_accum(conf_file_id) AS conf_file_ids
419 FROM conf_file_nodegroup
420 GROUP BY nodegroup_id;
422 --------------------------------------------------------------------------------
423 -- Node network interfaces
424 --------------------------------------------------------------------------------
426 -- Valid network addressing schemes
427 CREATE TABLE network_types (
428 type text PRIMARY KEY -- Addressing scheme
430 INSERT INTO network_types (type) VALUES ('ipv4');
432 -- Valid network configuration methods
433 CREATE TABLE network_methods (
434 method text PRIMARY KEY -- Configuration method
436 INSERT INTO network_methods (method) VALUES ('static');
437 INSERT INTO network_methods (method) VALUES ('dhcp');
438 INSERT INTO network_methods (method) VALUES ('proxy');
439 INSERT INTO network_methods (method) VALUES ('tap');
440 INSERT INTO network_methods (method) VALUES ('ipmi');
441 INSERT INTO network_methods (method) VALUES ('unknown');
443 -- Node network interfaces
444 CREATE TABLE nodenetworks (
446 nodenetwork_id serial PRIMARY KEY, -- Network interface identifier
447 node_id integer REFERENCES nodes NOT NULL, -- Which node
448 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
449 type text REFERENCES network_types NOT NULL, -- Addressing scheme
450 method text REFERENCES network_methods NOT NULL, -- Configuration method
452 -- Optional, depending on type and method
453 ip text, -- IP address
454 mac text, -- MAC address
455 gateway text, -- Default gateway address
456 network text, -- Network address
457 broadcast text, -- Network broadcast address
458 netmask text, -- Network mask
459 dns1 text, -- Primary DNS server
460 dns2 text, -- Secondary DNS server
461 bwlimit integer, -- Bandwidth limit in bps
462 hostname text -- Hostname of this interface
464 CREATE INDEX nodenetworks_node_id_idx ON nodenetworks (node_id);
466 -- Ordered by primary interface first
467 CREATE VIEW nodenetworks_ordered AS
468 SELECT node_id, nodenetwork_id
470 ORDER BY is_primary DESC;
472 -- Network interfaces on each node
473 CREATE VIEW node_nodenetworks AS
475 array_accum(nodenetwork_id) AS nodenetwork_ids
476 FROM nodenetworks_ordered
479 --------------------------------------------------------------------------------
480 -- Power control units (PCUs)
481 --------------------------------------------------------------------------------
485 pcu_id serial PRIMARY KEY, -- PCU identifier
486 site_id integer REFERENCES sites NOT NULL, -- Site identifier
487 hostname text, -- Hostname, not necessarily unique (multiple logical sites could use the same PCU)
488 ip text NOT NULL, -- IP, not necessarily unique
491 protocol text, -- Protocol, e.g. ssh or https or telnet
492 username text, -- Username, if applicable
493 "password" text, -- Password, if applicable
494 model text, -- Model, e.g. BayTech or iPal
495 notes text -- Random notes
497 CREATE INDEX pcus_site_id_idx ON pcus (site_id);
499 CREATE VIEW site_pcus AS
501 array_accum(pcu_id) AS pcu_ids
505 CREATE TABLE pcu_node (
506 pcu_id integer REFERENCES pcus NOT NULL, -- PCU identifier
507 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
508 port integer NOT NULL, -- Port number
509 PRIMARY KEY (pcu_id, node_id), -- The same node cannot be controlled by different ports
510 UNIQUE (pcu_id, port) -- The same port cannot control multiple nodes
512 CREATE INDEX pcu_node_pcu_id_idx ON pcu_node (pcu_id);
513 CREATE INDEX pcu_node_node_id_idx ON pcu_node (node_id);
515 CREATE VIEW node_pcus AS
517 array_accum(pcu_id) AS pcu_ids,
518 array_accum(port) AS ports
522 CREATE VIEW pcu_nodes AS
524 array_accum(node_id) AS node_ids,
525 array_accum(port) AS ports
529 --------------------------------------------------------------------------------
531 --------------------------------------------------------------------------------
533 CREATE TABLE slice_instantiations (
534 instantiation text PRIMARY KEY
536 INSERT INTO slice_instantiations (instantiation) VALUES ('not-instantiated'); -- Placeholder slice
537 INSERT INTO slice_instantiations (instantiation) VALUES ('plc-instantiated'); -- Instantiated by Node Manager
538 INSERT INTO slice_instantiations (instantiation) VALUES ('delegated'); -- Manually instantiated
541 CREATE TABLE slices (
542 slice_id serial PRIMARY KEY, -- Slice identifier
543 -- xxx temporarily remove the NOT NULL constraint
544 site_id integer REFERENCES sites, -- Site identifier
545 name text NOT NULL, -- Slice name
546 instantiation text REFERENCES slice_instantiations NOT NULL DEFAULT 'plc-instantiated', -- Slice state, e.g. plc-instantiated
547 url text, -- Project URL
548 description text, -- Project description
550 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
552 -- xxx temporarily remove the NOT NULL constraint
553 creator_person_id integer REFERENCES persons, -- Creator
554 created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation date
555 expires timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP + '2 weeks', -- Expiration date
557 is_deleted boolean NOT NULL DEFAULT false
559 CREATE INDEX slices_site_id_idx ON slices (site_id) WHERE is_deleted IS false;
560 CREATE INDEX slices_name_idx ON slices (name) WHERE is_deleted IS false;
563 CREATE TABLE slice_node (
564 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
565 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
566 PRIMARY KEY (slice_id, node_id)
568 CREATE INDEX slice_node_slice_id_idx ON slice_node (slice_id);
569 CREATE INDEX slice_node_node_id_idx ON slice_node (node_id);
571 -- Synonym for slice_node
572 CREATE VIEW slivers AS
573 SELECT * FROM slice_node;
575 -- Nodes in each slice
576 CREATE VIEW slice_nodes AS
578 array_accum(node_id) AS node_ids
582 -- Slices on each node
583 CREATE VIEW node_slices AS
585 array_accum(slice_id) AS slice_ids
589 -- Slices at each site
590 CREATE VIEW site_slices AS
592 array_accum(slice_id) AS slice_ids
594 WHERE is_deleted is false
597 -- Slices - peer relationship
598 CREATE TABLE peer_slice (
599 peer_id integer REFERENCES peers NOT NULL, -- peer primary key
600 slice_id integer REFERENCES slices NOT NULL, -- node primary key
601 PRIMARY KEY (peer_id, slice_id)
603 CREATE INDEX peer_slice_peer_id_idx ON peer_slice (peer_id);
604 CREATE INDEX peer_slice_slice_id_idx ON peer_slice (slice_id);
606 CREATE VIEW peer_slices AS
608 array_accum(slice_id) AS slice_ids
613 CREATE TABLE slice_person (
614 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
615 person_id integer REFERENCES persons NOT NULL, -- Account identifier
616 PRIMARY KEY (slice_id, person_id)
618 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
619 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
621 -- Members of the slice
622 CREATE VIEW slice_persons AS
624 array_accum(person_id) AS person_ids
628 -- Slices of which each person is a member
629 CREATE VIEW person_slices AS
631 array_accum(slice_id) AS slice_ids
635 --------------------------------------------------------------------------------
637 --------------------------------------------------------------------------------
639 -- Slice attribute types
640 CREATE TABLE slice_attribute_types (
641 attribute_type_id serial PRIMARY KEY, -- Attribute type identifier
642 name text UNIQUE NOT NULL, -- Attribute name
643 description text, -- Attribute description
644 min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can set or change this attribute
647 -- Slice/sliver attributes
648 CREATE TABLE slice_attribute (
649 slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
650 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
651 node_id integer REFERENCES nodes, -- Sliver attribute if set
652 attribute_type_id integer REFERENCES slice_attribute_types NOT NULL, -- Attribute type identifier
655 CREATE INDEX slice_attribute_slice_id_idx ON slice_attribute (slice_id);
656 CREATE INDEX slice_attribute_node_id_idx ON slice_attribute (node_id);
658 CREATE VIEW slice_attributes AS
660 array_accum(slice_attribute_id) AS slice_attribute_ids
664 --------------------------------------------------------------------------------
665 -- Authenticated sessions
666 --------------------------------------------------------------------------------
668 -- Authenticated sessions
669 CREATE TABLE sessions (
670 session_id text PRIMARY KEY, -- Session identifier
671 expires timestamp without time zone
674 -- People can have multiple sessions
675 CREATE TABLE person_session (
676 person_id integer REFERENCES persons NOT NULL, -- Account identifier
677 session_id text REFERENCES sessions NOT NULL, -- Session identifier
678 PRIMARY KEY (person_id, session_id),
679 UNIQUE (session_id) -- Sessions are unique
681 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
683 -- Nodes can have only one session
684 CREATE TABLE node_session (
685 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
686 session_id text REFERENCES sessions NOT NULL, -- Session identifier
687 UNIQUE (node_id), -- Nodes can have only one session
688 UNIQUE (session_id) -- Sessions are unique
691 --------------------------------------------------------------------------------
693 --------------------------------------------------------------------------------
695 CREATE TABLE messages (
696 message_id text PRIMARY KEY, -- Message name
697 subject text, -- Message summary
698 template text, -- Message template
699 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
702 --------------------------------------------------------------------------------
704 --------------------------------------------------------------------------------
707 CREATE TABLE event_types (
708 event_type text PRIMARY KEY -- Event type
710 INSERT INTO event_types (event_type) VALUES ('Add');
711 INSERT INTO event_types (event_type) VALUES ('AddTo');
712 INSERT INTO event_types (event_type) VALUES ('Get');
713 INSERT INTO event_types (event_type) VALUES ('Update');
714 INSERT INTO event_types (event_type) VALUES ('Delete');
715 INSERT INTO event_types (event_type) VALUES ('DeleteFrom');
716 INSERT INTO event_types (event_type) VALUES ('Unknown');
719 CREATE TABLE object_types (
720 object_type text PRIMARY KEY -- Object type
722 INSERT INTO object_types (object_type) VALUES ('AddressType');
723 INSERT INTO object_types (object_type) VALUES ('Address');
724 INSERT INTO object_types (object_type) VALUES ('BootState');
725 INSERT INTO object_types (object_type) VALUES ('ConfFile');
726 INSERT INTO object_types (object_type) VALUES ('KeyType');
727 INSERT INTO object_types (object_type) VALUES ('Key');
728 INSERT INTO object_types (object_type) VALUES ('Message');
729 INSERT INTO object_types (object_type) VALUES ('NetworkMethod');
730 INSERT INTO object_types (object_type) VALUES ('NetworkType');
731 INSERT INTO object_types (object_type) VALUES ('Network');
732 INSERT INTO object_types (object_type) VALUES ('NodeGroup');
733 INSERT INTO object_types (object_type) VALUES ('NodeNetwork');
734 INSERT INTO object_types (object_type) VALUES ('Node');
735 INSERT INTO object_types (object_type) VALUES ('PCU');
736 INSERT INTO object_types (object_type) VALUES ('Person');
737 INSERT INTO object_types (object_type) VALUES ('Role');
738 INSERT INTO object_types (object_type) VALUES ('Session');
739 INSERT INTO object_types (object_type) VALUES ('Site');
740 INSERT INTO object_types (object_type) VALUES ('SliceAttributeType');
741 INSERT INTO object_types (object_type) VALUES ('SliceAttribute');
742 INSERT INTO object_types (object_type) VALUES ('Slice');
743 INSERT INTO object_types (object_type) VALUES ('SliceInstantiation');
744 INSERT INTO object_types (object_type) VALUES ('Unknown');
747 CREATE TABLE events (
748 event_id serial PRIMARY KEY, -- Event identifier
749 person_id integer REFERENCES persons, -- Person responsible for event, if any
750 node_id integer REFERENCES nodes, -- Node responsible for event, if any
751 event_type text REFERENCES event_types NOT NULL DEFAULT 'Unknown', -- Event type
752 object_type text REFERENCES object_types NOT NULL DEFAULT 'Unknown', -- Object type associated with event
753 fault_code integer NOT NULL DEFAULT 0, -- Did this event result in error
754 call text NOT NULL, -- Call responsible for this event
755 runtime float, -- Event run time
756 time timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP -- Event timestamp
760 CREATE TABLE event_object (
761 event_id integer REFERENCES events NOT NULL, -- Event identifier
762 object_id integer NOT NULL -- Object identifier
764 CREATE INDEX event_object_event_id_idx ON event_object (event_id);
765 CREATE INDEX event_object_object_id_idx ON event_object (object_id);
767 CREATE VIEW event_objects AS
769 array_accum(object_id) AS object_ids
773 --------------------------------------------------------------------------------
775 --------------------------------------------------------------------------------
777 CREATE VIEW view_events AS
787 CAST(date_part('epoch', events.time) AS bigint) AS time,
788 COALESCE(event_objects.object_ids, '{}') AS object_ids
790 LEFT JOIN event_objects USING (event_id);
792 CREATE VIEW view_persons AS
801 persons.verification_key,
802 persons.verification_expires,
807 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
808 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
809 COALESCE(person_roles.role_ids, '{}') AS role_ids,
810 COALESCE(person_roles.roles, '{}') AS roles,
811 COALESCE(person_sites.site_ids, '{}') AS site_ids,
812 COALESCE(person_keys.key_ids, '{}') AS key_ids,
813 COALESCE(person_slices.slice_ids, '{}') AS slice_ids
815 LEFT JOIN person_roles USING (person_id)
816 LEFT JOIN person_sites USING (person_id)
817 LEFT JOIN person_keys USING (person_id)
818 LEFT JOIN person_slices USING (person_id);
820 CREATE VIEW view_nodes AS
832 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
833 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
834 COALESCE(node_nodenetworks.nodenetwork_ids, '{}') AS nodenetwork_ids,
835 COALESCE(node_nodegroups.nodegroup_ids, '{}') AS nodegroup_ids,
836 COALESCE(node_slices.slice_ids, '{}') AS slice_ids,
837 COALESCE(node_pcus.pcu_ids, '{}') AS pcu_ids,
838 COALESCE(node_pcus.ports, '{}') AS ports,
839 COALESCE(node_conf_files.conf_file_ids, '{}') AS conf_file_ids,
840 node_session.session_id AS session
842 LEFT JOIN peer_node USING (node_id)
843 LEFT JOIN node_nodenetworks USING (node_id)
844 LEFT JOIN node_nodegroups USING (node_id)
845 LEFT JOIN node_slices USING (node_id)
846 LEFT JOIN node_pcus USING (node_id)
847 LEFT JOIN node_conf_files USING (node_id)
848 LEFT JOIN node_session USING (node_id)
849 WHERE peer_node.peer_id IS NULL;
851 CREATE VIEW view_peers AS
855 peer_slices.slice_ids
857 LEFT JOIN peer_nodes USING (peer_id)
858 LEFT JOIN peer_slices USING (peer_id);
860 CREATE VIEW view_foreign_nodes AS
868 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
869 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
870 COALESCE(node_slices.slice_ids, '{}') AS slice_ids,
873 LEFT JOIN peer_node USING (node_id)
874 LEFT JOIN node_slices USING (node_id)
875 WHERE peer_node.peer_id IS NOT NULL;
877 CREATE VIEW view_nodegroups AS
879 nodegroups.nodegroup_id,
881 nodegroups.description,
882 COALESCE(nodegroup_nodes.node_ids, '{}') AS node_ids,
883 COALESCE(nodegroup_conf_files.conf_file_ids, '{}') AS conf_file_ids
885 LEFT JOIN nodegroup_nodes USING (nodegroup_id)
886 LEFT JOIN nodegroup_conf_files USING (nodegroup_id);
888 CREATE VIEW view_conf_files AS
890 conf_files.conf_file_id,
894 conf_files.file_permissions,
895 conf_files.file_owner,
896 conf_files.file_group,
897 conf_files.preinstall_cmd,
898 conf_files.postinstall_cmd,
899 conf_files.error_cmd,
900 conf_files.ignore_cmd_errors,
901 conf_files.always_update,
902 COALESCE(conf_file_nodes.node_ids, '{}') AS node_ids,
903 COALESCE(conf_file_nodegroups.nodegroup_ids, '{}') AS nodegroup_ids
905 LEFT JOIN conf_file_nodes USING (conf_file_id)
906 LEFT JOIN conf_file_nodegroups USING (conf_file_id);
908 CREATE VIEW view_pcus AS
919 COALESCE(pcu_nodes.node_ids, '{}') AS node_ids,
920 COALESCE(pcu_nodes.ports, '{}') AS ports
922 LEFT JOIN pcu_nodes USING (pcu_id);
924 CREATE VIEW view_sites AS
929 sites.abbreviated_name,
937 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
938 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
939 COALESCE(site_persons.person_ids, '{}') AS person_ids,
940 COALESCE(site_nodes.node_ids, '{}') AS node_ids,
941 COALESCE(site_addresses.address_ids, '{}') AS address_ids,
942 COALESCE(site_slices.slice_ids, '{}') AS slice_ids,
943 COALESCE(site_pcus.pcu_ids, '{}') AS pcu_ids
945 LEFT JOIN site_persons USING (site_id)
946 LEFT JOIN site_nodes USING (site_id)
947 LEFT JOIN site_addresses USING (site_id)
948 LEFT JOIN site_slices USING (site_id)
949 LEFT JOIN site_pcus USING (site_id);
951 CREATE VIEW view_addresses AS
953 addresses.address_id,
959 addresses.postalcode,
961 COALESCE(address_address_types.address_type_ids, '{}') AS address_type_ids,
962 COALESCE(address_address_types.address_types, '{}') AS address_types
964 LEFT JOIN address_address_types USING (address_id);
966 CREATE VIEW view_slices AS
971 slices.instantiation,
975 slices.creator_person_id,
977 CAST(date_part('epoch', slices.created) AS bigint) AS created,
978 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
979 COALESCE(slice_nodes.node_ids, '{}') AS node_ids,
980 COALESCE(slice_persons.person_ids, '{}') AS person_ids,
981 COALESCE(slice_attributes.slice_attribute_ids, '{}') AS slice_attribute_ids
983 LEFT JOIN peer_slice USING (slice_id)
984 LEFT JOIN slice_nodes USING (slice_id)
985 LEFT JOIN slice_persons USING (slice_id)
986 LEFT JOIN slice_attributes USING (slice_id)
987 WHERE peer_slice.peer_id IS NULL
988 AND slices.site_id IS NOT NULL
989 AND slices.creator_person_id IS NOT NULL;
991 CREATE VIEW view_foreign_slices AS
996 slices.instantiation,
1001 CAST(date_part('epoch', slices.created) AS bigint) AS created,
1002 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
1003 COALESCE(slice_nodes.node_ids, '{}') AS node_ids
1005 LEFT JOIN peer_slice USING (slice_id)
1006 LEFT JOIN slice_nodes USING (slice_id)
1007 WHERE peer_slice.peer_id IS NOT NULL;
1010 CREATE VIEW view_slice_attributes AS
1012 slice_attribute.slice_attribute_id,
1013 slice_attribute.slice_id,
1014 slice_attribute.node_id,
1015 slice_attribute_types.attribute_type_id,
1016 slice_attribute_types.name,
1017 slice_attribute_types.description,
1018 slice_attribute_types.min_role_id,
1019 slice_attribute.value
1020 FROM slice_attribute
1021 INNER JOIN slice_attribute_types USING (attribute_type_id);
1023 CREATE VIEW view_sessions AS
1025 sessions.session_id,
1026 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
1027 person_session.person_id,
1028 node_session.node_id
1030 LEFT JOIN person_session USING (session_id)
1031 LEFT JOIN node_session USING (session_id);
1033 --------------------------------------------------------------------------------
1034 -- Built-in maintenance account and default site
1035 --------------------------------------------------------------------------------
1038 (first_name, last_name, email, password, enabled)
1040 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
1042 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
1043 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
1044 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
1045 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
1048 (login_base, name, abbreviated_name, max_slices)
1050 ('pl', 'PlanetLab Central', 'PLC', 100);