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.35 2006/11/15 10:59:54 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 deleted boolean NOT NULL DEFAULT false
559 CREATE INDEX slices_site_id_idx ON slices (site_id) WHERE deleted IS false;
560 CREATE INDEX slices_name_idx ON slices (name) WHERE 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
596 -- Slices - peer relationship
597 CREATE TABLE peer_slice (
598 peer_id integer REFERENCES peers NOT NULL, -- peer primary key
599 slice_id integer REFERENCES slices NOT NULL, -- node primary key
600 PRIMARY KEY (peer_id, slice_id)
602 CREATE INDEX peer_slice_peer_id_idx ON peer_slice (peer_id);
603 CREATE INDEX peer_slice_slice_id_idx ON peer_slice (slice_id);
605 CREATE VIEW peer_slices AS
607 array_accum(slice_id) AS slice_ids
612 CREATE TABLE slice_person (
613 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
614 person_id integer REFERENCES persons NOT NULL, -- Account identifier
615 PRIMARY KEY (slice_id, person_id)
617 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
618 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
620 -- Members of the slice
621 CREATE VIEW slice_persons AS
623 array_accum(person_id) AS person_ids
627 -- Slices of which each person is a member
628 CREATE VIEW person_slices AS
630 array_accum(slice_id) AS slice_ids
634 --------------------------------------------------------------------------------
636 --------------------------------------------------------------------------------
638 -- Slice attribute types
639 CREATE TABLE slice_attribute_types (
640 attribute_type_id serial PRIMARY KEY, -- Attribute type identifier
641 name text UNIQUE NOT NULL, -- Attribute name
642 description text, -- Attribute description
643 min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can set or change this attribute
646 -- Slice/sliver attributes
647 CREATE TABLE slice_attribute (
648 slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
649 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
650 node_id integer REFERENCES nodes, -- Sliver attribute if set
651 attribute_type_id integer REFERENCES slice_attribute_types NOT NULL, -- Attribute type identifier
654 CREATE INDEX slice_attribute_slice_id_idx ON slice_attribute (slice_id);
655 CREATE INDEX slice_attribute_node_id_idx ON slice_attribute (node_id);
657 CREATE VIEW slice_attributes AS
659 array_accum(slice_attribute_id) AS slice_attribute_ids
663 --------------------------------------------------------------------------------
664 -- Authenticated sessions
665 --------------------------------------------------------------------------------
667 -- Authenticated sessions
668 CREATE TABLE sessions (
669 session_id text PRIMARY KEY, -- Session identifier
670 expires timestamp without time zone
673 -- People can have multiple sessions
674 CREATE TABLE person_session (
675 person_id integer REFERENCES persons NOT NULL, -- Account identifier
676 session_id text REFERENCES sessions NOT NULL, -- Session identifier
677 PRIMARY KEY (person_id, session_id),
678 UNIQUE (session_id) -- Sessions are unique
680 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
682 -- Nodes can have only one session
683 CREATE TABLE node_session (
684 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
685 session_id text REFERENCES sessions NOT NULL, -- Session identifier
686 UNIQUE (node_id), -- Nodes can have only one session
687 UNIQUE (session_id) -- Sessions are unique
690 --------------------------------------------------------------------------------
692 --------------------------------------------------------------------------------
694 CREATE TABLE messages (
695 message_id text PRIMARY KEY, -- Message name
696 template text, -- Message template
697 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
700 --------------------------------------------------------------------------------
702 --------------------------------------------------------------------------------
705 CREATE TABLE event_types (
706 event_type text PRIMARY KEY -- Event type
708 INSERT INTO event_types (event_type) VALUES ('Add');
709 INSERT INTO event_types (event_type) VALUES ('AddTo');
710 INSERT INTO event_types (event_type) VALUES ('Get');
711 INSERT INTO event_types (event_type) VALUES ('Update');
712 INSERT INTO event_types (event_type) VALUES ('Delete');
713 INSERT INTO event_types (event_type) VALUES ('DeleteFrom');
714 INSERT INTO event_types (event_type) VALUES ('Unknown');
717 CREATE TABLE object_types (
718 object_type text PRIMARY KEY -- Object type
720 INSERT INTO object_types (object_type) VALUES ('AddressType');
721 INSERT INTO object_types (object_type) VALUES ('Address');
722 INSERT INTO object_types (object_type) VALUES ('BootState');
723 INSERT INTO object_types (object_type) VALUES ('ConfFile');
724 INSERT INTO object_types (object_type) VALUES ('KeyType');
725 INSERT INTO object_types (object_type) VALUES ('Key');
726 INSERT INTO object_types (object_type) VALUES ('NetworkMethod');
727 INSERT INTO object_types (object_type) VALUES ('NetworkType');
728 INSERT INTO object_types (object_type) VALUES ('Network');
729 INSERT INTO object_types (object_type) VALUES ('NodeGroup');
730 INSERT INTO object_types (object_type) VALUES ('NodeNetwork');
731 INSERT INTO object_types (object_type) VALUES ('Node');
732 INSERT INTO object_types (object_type) VALUES ('PCU');
733 INSERT INTO object_types (object_type) VALUES ('Person');
734 INSERT INTO object_types (object_type) VALUES ('Role');
735 INSERT INTO object_types (object_type) VALUES ('Session');
736 INSERT INTO object_types (object_type) VALUES ('Site');
737 INSERT INTO object_types (object_type) VALUES ('SliceAttributeType');
738 INSERT INTO object_types (object_type) VALUES ('SliceAttribute');
739 INSERT INTO object_types (object_type) VALUES ('Slice');
740 INSERT INTO object_types (object_type) VALUES ('Unknown');
743 CREATE TABLE events (
744 event_id serial PRIMARY KEY, -- Event identifier
745 person_id integer REFERENCES persons, -- Person responsible for event, if any
746 node_id integer REFERENCES nodes, -- Node responsible for event, if any
747 event_type text REFERENCES event_types NOT NULL DEFAULT 'Unknown', -- Event type
748 object_type text REFERENCES object_types NOT NULL DEFAULT 'Unknown', -- Object type associated with event
749 fault_code integer NOT NULL DEFAULT 0, -- Did this event result in error
750 call text NOT NULL, -- Call responsible for this event
751 runtime float, -- Event run time
752 time timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP -- Event timestamp
756 CREATE TABLE event_object (
757 event_id integer REFERENCES events NOT NULL, -- Event identifier
758 object_id integer NOT NULL -- Object identifier
760 CREATE INDEX event_object_event_id_idx ON event_object (event_id);
761 CREATE INDEX event_object_object_id_idx ON event_object (object_id);
763 CREATE VIEW event_objects AS
765 array_accum(object_id) AS object_ids
769 --------------------------------------------------------------------------------
771 --------------------------------------------------------------------------------
773 CREATE VIEW view_events AS
783 CAST(date_part('epoch', events.time) AS bigint) AS time,
784 COALESCE(event_objects.object_ids, '{}') AS object_ids
786 LEFT JOIN event_objects USING (event_id);
788 CREATE VIEW view_persons AS
797 persons.verification_key,
798 persons.verification_expires,
803 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
804 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
805 COALESCE(person_roles.role_ids, '{}') AS role_ids,
806 COALESCE(person_roles.roles, '{}') AS roles,
807 COALESCE(person_sites.site_ids, '{}') AS site_ids,
808 COALESCE(person_keys.key_ids, '{}') AS key_ids,
809 COALESCE(person_slices.slice_ids, '{}') AS slice_ids
811 LEFT JOIN person_roles USING (person_id)
812 LEFT JOIN person_sites USING (person_id)
813 LEFT JOIN person_keys USING (person_id)
814 LEFT JOIN person_slices USING (person_id);
816 CREATE VIEW view_nodes AS
828 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
829 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
830 COALESCE(node_nodenetworks.nodenetwork_ids, '{}') AS nodenetwork_ids,
831 COALESCE(node_nodegroups.nodegroup_ids, '{}') AS nodegroup_ids,
832 COALESCE(node_slices.slice_ids, '{}') AS slice_ids,
833 COALESCE(node_pcus.pcu_ids, '{}') AS pcu_ids,
834 COALESCE(node_pcus.ports, '{}') AS ports,
835 COALESCE(node_conf_files.conf_file_ids, '{}') AS conf_file_ids,
836 node_session.session_id AS session
838 LEFT JOIN peer_node USING (node_id)
839 LEFT JOIN node_nodenetworks USING (node_id)
840 LEFT JOIN node_nodegroups USING (node_id)
841 LEFT JOIN node_slices USING (node_id)
842 LEFT JOIN node_pcus USING (node_id)
843 LEFT JOIN node_conf_files USING (node_id)
844 LEFT JOIN node_session USING (node_id)
845 WHERE peer_node.peer_id IS NULL;
847 CREATE VIEW view_peers AS
851 peer_slices.slice_ids
853 LEFT JOIN peer_nodes USING (peer_id)
854 LEFT JOIN peer_slices USING (peer_id);
856 CREATE VIEW view_foreign_nodes AS
864 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
865 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
866 COALESCE(node_slices.slice_ids, '{}') AS slice_ids,
869 LEFT JOIN peer_node USING (node_id)
870 LEFT JOIN node_slices USING (node_id)
871 WHERE peer_node.peer_id IS NOT NULL;
873 CREATE VIEW view_nodegroups AS
875 nodegroups.nodegroup_id,
877 nodegroups.description,
878 COALESCE(nodegroup_nodes.node_ids, '{}') AS node_ids,
879 COALESCE(nodegroup_conf_files.conf_file_ids, '{}') AS conf_file_ids
881 LEFT JOIN nodegroup_nodes USING (nodegroup_id)
882 LEFT JOIN nodegroup_conf_files USING (nodegroup_id);
884 CREATE VIEW view_conf_files AS
886 conf_files.conf_file_id,
890 conf_files.file_permissions,
891 conf_files.file_owner,
892 conf_files.file_group,
893 conf_files.preinstall_cmd,
894 conf_files.postinstall_cmd,
895 conf_files.error_cmd,
896 conf_files.ignore_cmd_errors,
897 conf_files.always_update,
898 COALESCE(conf_file_nodes.node_ids, '{}') AS node_ids,
899 COALESCE(conf_file_nodegroups.nodegroup_ids, '{}') AS nodegroup_ids
901 LEFT JOIN conf_file_nodes USING (conf_file_id)
902 LEFT JOIN conf_file_nodegroups USING (conf_file_id);
904 CREATE VIEW view_pcus AS
915 COALESCE(pcu_nodes.node_ids, '{}') AS node_ids,
916 COALESCE(pcu_nodes.ports, '{}') AS ports
918 LEFT JOIN pcu_nodes USING (pcu_id);
920 CREATE VIEW view_sites AS
925 sites.abbreviated_name,
933 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
934 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
935 COALESCE(site_persons.person_ids, '{}') AS person_ids,
936 COALESCE(site_nodes.node_ids, '{}') AS node_ids,
937 COALESCE(site_addresses.address_ids, '{}') AS address_ids,
938 COALESCE(site_slices.slice_ids, '{}') AS slice_ids,
939 COALESCE(site_pcus.pcu_ids, '{}') AS pcu_ids
941 LEFT JOIN site_persons USING (site_id)
942 LEFT JOIN site_nodes USING (site_id)
943 LEFT JOIN site_addresses USING (site_id)
944 LEFT JOIN site_slices USING (site_id)
945 LEFT JOIN site_pcus USING (site_id);
947 CREATE VIEW view_addresses AS
949 addresses.address_id,
955 addresses.postalcode,
957 COALESCE(address_address_types.address_type_ids, '{}') AS address_type_ids,
958 COALESCE(address_address_types.address_types, '{}') AS address_types
960 LEFT JOIN address_address_types USING (address_id);
962 CREATE VIEW view_slices AS
967 slices.instantiation,
971 slices.creator_person_id,
973 CAST(date_part('epoch', slices.created) AS bigint) AS created,
974 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
975 COALESCE(slice_nodes.node_ids, '{}') AS node_ids,
976 COALESCE(slice_persons.person_ids, '{}') AS person_ids,
977 COALESCE(slice_attributes.slice_attribute_ids, '{}') AS slice_attribute_ids
979 LEFT JOIN peer_slice USING (slice_id)
980 LEFT JOIN slice_nodes USING (slice_id)
981 LEFT JOIN slice_persons USING (slice_id)
982 LEFT JOIN slice_attributes USING (slice_id)
983 WHERE peer_slice.peer_id IS NULL
984 AND slices.site_id IS NOT NULL
985 AND slices.creator_person_id IS NOT NULL;
987 CREATE VIEW view_foreign_slices AS
992 slices.instantiation,
997 CAST(date_part('epoch', slices.created) AS bigint) AS created,
998 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
999 COALESCE(slice_nodes.node_ids, '{}') AS node_ids
1001 LEFT JOIN peer_slice USING (slice_id)
1002 LEFT JOIN slice_nodes USING (slice_id)
1003 WHERE peer_slice.peer_id IS NOT NULL;
1006 CREATE VIEW view_slice_attributes AS
1008 slice_attribute.slice_attribute_id,
1009 slice_attribute.slice_id,
1010 slice_attribute.node_id,
1011 slice_attribute_types.attribute_type_id,
1012 slice_attribute_types.name,
1013 slice_attribute_types.description,
1014 slice_attribute_types.min_role_id,
1015 slice_attribute.value
1016 FROM slice_attribute
1017 INNER JOIN slice_attribute_types USING (attribute_type_id);
1019 CREATE VIEW view_sessions AS
1021 sessions.session_id,
1022 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
1023 person_session.person_id,
1024 node_session.node_id
1026 LEFT JOIN person_session USING (session_id)
1027 LEFT JOIN node_session USING (session_id);
1029 --------------------------------------------------------------------------------
1030 -- Built-in maintenance account and default site
1031 --------------------------------------------------------------------------------
1034 (first_name, last_name, email, password, enabled)
1036 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
1038 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
1039 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
1040 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
1041 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
1044 (login_base, name, abbreviated_name, max_slices)
1046 ('pl', 'PlanetLab Central', 'PLC', 100);