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.43 2006/11/23 19:35:38 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 --------------------------------------------------------------------------------
45 peer_id serial PRIMARY KEY, -- identifier
46 peername text NOT NULL, -- free text
47 peer_url text NOT NULL, -- the url of that peer's API
48 -- oops, looks like we have a dependency loop here
49 --person_id integer REFERENCES persons NOT NULL, -- the account we use for logging in
50 person_id integer NOT NULL, -- the account we use for logging in
52 deleted boolean NOT NULL DEFAULT false
55 --------------------------------------------------------------------------------
57 --------------------------------------------------------------------------------
60 CREATE TABLE persons (
62 person_id serial PRIMARY KEY, -- Account identifier
63 email text NOT NULL, -- E-mail address
64 first_name text NOT NULL, -- First name
65 last_name text NOT NULL, -- Last name
66 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
67 enabled boolean NOT NULL DEFAULT false, -- Has been disabled
70 password text NOT NULL, -- Password (md5crypted)
71 verification_key text, -- Reset password key
72 verification_expires timestamp without time zone,
75 title text, -- Honorific
76 phone text, -- Telephone number
77 url text, -- Home page
78 bio text, -- Biography
81 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
82 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
84 peer_id integer REFERENCES peers -- From which peer
86 CREATE INDEX persons_email_idx ON persons (email) WHERE deleted IS false;
88 --------------------------------------------------------------------------------
90 --------------------------------------------------------------------------------
95 site_id serial PRIMARY KEY, -- Site identifier
96 login_base text NOT NULL, -- Site slice prefix
97 name text NOT NULL, -- Site name
98 abbreviated_name text NOT NULL, -- Site abbreviated name
99 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
100 is_public boolean NOT NULL DEFAULT true, -- Shows up in public lists
101 max_slices integer NOT NULL DEFAULT 0, -- Maximum number of slices
102 max_slivers integer NOT NULL DEFAULT 1000, -- Maximum number of instantiated slivers
110 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
111 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
113 CREATE INDEX sites_login_base_idx ON sites (login_base) WHERE deleted IS false;
115 -- Account site membership
116 CREATE TABLE person_site (
117 person_id integer REFERENCES persons NOT NULL, -- Account identifier
118 site_id integer REFERENCES sites NOT NULL, -- Site identifier
119 is_primary boolean NOT NULL DEFAULT false, -- Is the primary site for this account
120 PRIMARY KEY (person_id, site_id)
122 CREATE INDEX person_site_person_id_idx ON person_site (person_id);
123 CREATE INDEX person_site_site_id_idx ON person_site (site_id);
125 -- Ordered by primary site first
126 CREATE VIEW person_site_ordered AS
127 SELECT person_id, site_id
129 ORDER BY is_primary DESC;
131 -- Sites that each person is a member of
132 CREATE VIEW person_sites AS
134 array_accum(site_id) AS site_ids
135 FROM person_site_ordered
138 -- Accounts at each site
139 CREATE VIEW site_persons AS
141 array_accum(person_id) AS person_ids
145 --------------------------------------------------------------------------------
147 --------------------------------------------------------------------------------
149 CREATE TABLE address_types (
150 address_type_id serial PRIMARY KEY, -- Address type identifier
151 name text UNIQUE NOT NULL, -- Address type
152 description text -- Address type description
155 INSERT INTO address_types (name) VALUES ('Personal');
156 INSERT INTO address_types (name) VALUES ('Shipping');
157 -- XXX Used to be Site
158 INSERT INTO address_types (name) VALUES ('Billing');
161 CREATE TABLE addresses (
162 address_id serial PRIMARY KEY, -- Address identifier
163 line1 text NOT NULL, -- Address line 1
164 line2 text, -- Address line 2
165 line3 text, -- Address line 3
166 city text NOT NULL, -- City
167 state text NOT NULL, -- State or province
168 postalcode text NOT NULL, -- Postal code
169 country text NOT NULL -- Country
172 -- Each mailing address can be one of several types
173 CREATE TABLE address_address_type (
174 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
175 address_type_id integer REFERENCES address_types NOT NULL, -- Address type
176 PRIMARY KEY (address_id, address_type_id)
178 CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
179 CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);
181 CREATE VIEW address_address_types AS
183 array_accum(address_type_id) AS address_type_ids,
184 array_accum(address_types.name) AS address_types
185 FROM address_address_type
186 LEFT JOIN address_types USING (address_type_id)
189 CREATE TABLE site_address (
190 site_id integer REFERENCES sites NOT NULL, -- Site identifier
191 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
192 PRIMARY KEY (site_id, address_id)
194 CREATE INDEX site_address_site_id_idx ON site_address (site_id);
195 CREATE INDEX site_address_address_id_idx ON site_address (address_id);
197 CREATE VIEW site_addresses AS
199 array_accum(address_id) AS address_ids
203 --------------------------------------------------------------------------------
204 -- Authentication Keys
205 --------------------------------------------------------------------------------
208 CREATE TABLE key_types (
209 key_type text PRIMARY KEY -- Key type
211 INSERT INTO key_types (key_type) VALUES ('ssh');
213 -- Authentication keys
215 key_id serial PRIMARY KEY, -- Key identifier
216 key_type text REFERENCES key_types NOT NULL, -- Key type
217 key text NOT NULL, -- Key material
218 is_blacklisted boolean NOT NULL DEFAULT false, -- Has been blacklisted
219 peer_id integer REFERENCES peers -- From which peer
222 -- Account authentication key(s)
223 CREATE TABLE person_key (
224 person_id integer REFERENCES persons NOT NULL, -- Account identifier
225 key_id integer REFERENCES keys NOT NULL, -- Key identifier
226 PRIMARY KEY (person_id, key_id)
228 CREATE INDEX person_key_person_id_idx ON person_key (person_id);
229 CREATE INDEX person_key_key_id_idx ON person_key (key_id);
231 CREATE VIEW person_keys AS
233 array_accum(key_id) AS key_ids
237 --------------------------------------------------------------------------------
239 --------------------------------------------------------------------------------
241 -- Valid account roles
243 role_id integer PRIMARY KEY, -- Role identifier
244 name text UNIQUE NOT NULL -- Role symbolic name
246 INSERT INTO roles (role_id, name) VALUES (10, 'admin');
247 INSERT INTO roles (role_id, name) VALUES (20, 'pi');
248 INSERT INTO roles (role_id, name) VALUES (30, 'user');
249 INSERT INTO roles (role_id, name) VALUES (40, 'tech');
250 INSERT INTO roles (role_id, name) VALUES (1000, 'node');
251 INSERT INTO roles (role_id, name) VALUES (2000, 'anonymous');
252 -- xxx not sure this us useful yet
253 --INSERT INTO roles (role_id, name) VALUES (3000, 'peer');
255 CREATE TABLE person_role (
256 person_id integer REFERENCES persons NOT NULL, -- Account identifier
257 role_id integer REFERENCES roles NOT NULL, -- Role identifier
258 PRIMARY KEY (person_id, role_id)
260 CREATE INDEX person_role_person_id_idx ON person_role (person_id);
263 CREATE VIEW person_roles AS
265 array_accum(role_id) AS role_ids,
266 array_accum(roles.name) AS roles
268 LEFT JOIN roles USING (role_id)
271 --------------------------------------------------------------------------------
273 --------------------------------------------------------------------------------
275 -- Valid node boot states
276 CREATE TABLE boot_states (
277 boot_state text PRIMARY KEY
279 INSERT INTO boot_states (boot_state) VALUES ('boot');
280 INSERT INTO boot_states (boot_state) VALUES ('dbg');
281 INSERT INTO boot_states (boot_state) VALUES ('inst');
282 INSERT INTO boot_states (boot_state) VALUES ('rins');
283 INSERT INTO boot_states (boot_state) VALUES ('rcnf');
284 INSERT INTO boot_states (boot_state) VALUES ('new');
289 node_id serial PRIMARY KEY, -- Node identifier
290 hostname text NOT NULL, -- Node hostname
291 -- temporarily removed NOT NULL clause for foreign_nodes
292 site_id integer REFERENCES sites, -- At which site
293 -- may be NULL for local_nodes
294 peer_id integer REFERENCES peers, -- From which peer
296 boot_state text REFERENCES boot_states NOT NULL DEFAULT 'inst', -- Node boot state
297 deleted boolean NOT NULL DEFAULT false, -- Is deleted
300 model text, -- Hardware make and model
301 boot_nonce text, -- Random nonce updated by Boot Manager
302 version text, -- Boot CD version string updated by Boot Manager
303 -- XXX Should be key_id integer REFERENCES keys
304 ssh_rsa_key text, -- SSH host key updated by Boot Manager
305 key text, -- Node key generated by API when configuration file is downloaded
308 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
309 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
311 CREATE INDEX nodes_hostname_idx ON nodes (hostname) WHERE deleted IS false;
312 CREATE INDEX nodes_site_id_idx ON nodes (site_id) WHERE deleted IS false;
314 -- Nodes at each site
315 CREATE VIEW site_nodes AS
317 array_accum(node_id) AS node_ids
321 -- Nodes at each peer
322 CREATE VIEW peer_nodes AS
324 array_accum(node_id) AS node_ids
328 --------------------------------------------------------------------------------
330 --------------------------------------------------------------------------------
333 CREATE TABLE nodegroups (
334 nodegroup_id serial PRIMARY KEY, -- Group identifier
335 name text UNIQUE NOT NULL, -- Group name
336 description text -- Group description
339 -- Node group membership
340 CREATE TABLE nodegroup_node (
341 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Group identifier
342 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
343 PRIMARY KEY (nodegroup_id, node_id)
345 CREATE INDEX nodegroup_node_nodegroup_id_idx ON nodegroup_node (nodegroup_id);
346 CREATE INDEX nodegroup_node_node_id_idx ON nodegroup_node (node_id);
348 -- Nodes in each node group
349 CREATE VIEW nodegroup_nodes AS
351 array_accum(node_id) AS node_ids
353 GROUP BY nodegroup_id;
355 -- Node groups that each node is a member of
356 CREATE VIEW node_nodegroups AS
358 array_accum(nodegroup_id) AS nodegroup_ids
362 --------------------------------------------------------------------------------
363 -- Node configuration files
364 --------------------------------------------------------------------------------
366 CREATE TABLE conf_files (
367 conf_file_id serial PRIMARY KEY, -- Configuration file identifier
368 enabled bool NOT NULL DEFAULT true, -- Configuration file is active
369 source text NOT NULL, -- Relative path on the boot server where file can be downloaded
370 dest text NOT NULL, -- Absolute path where file should be installed
371 file_permissions text NOT NULL DEFAULT '0644', -- chmod(1) permissions
372 file_owner text NOT NULL DEFAULT 'root', -- chown(1) owner
373 file_group text NOT NULL DEFAULT 'root', -- chgrp(1) owner
374 preinstall_cmd text, -- Shell command to execute prior to installing
375 postinstall_cmd text, -- Shell command to execute after installing
376 error_cmd text, -- Shell command to execute if any error occurs
377 ignore_cmd_errors bool NOT NULL DEFAULT false, -- Install file anyway even if an error occurs
378 always_update bool NOT NULL DEFAULT false -- Always attempt to install file even if unchanged
381 CREATE TABLE conf_file_node (
382 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
383 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
384 PRIMARY KEY (conf_file_id, node_id)
386 CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
387 CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
389 -- Nodes linked to each configuration file
390 CREATE VIEW conf_file_nodes AS
392 array_accum(node_id) AS node_ids
394 GROUP BY conf_file_id;
396 -- Configuration files linked to each node
397 CREATE VIEW node_conf_files AS
399 array_accum(conf_file_id) AS conf_file_ids
403 CREATE TABLE conf_file_nodegroup (
404 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
405 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Node group identifier
406 PRIMARY KEY (conf_file_id, nodegroup_id)
408 CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
409 CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
411 -- Node groups linked to each configuration file
412 CREATE VIEW conf_file_nodegroups AS
414 array_accum(nodegroup_id) AS nodegroup_ids
415 FROM conf_file_nodegroup
416 GROUP BY conf_file_id;
418 -- Configuration files linked to each node group
419 CREATE VIEW nodegroup_conf_files AS
421 array_accum(conf_file_id) AS conf_file_ids
422 FROM conf_file_nodegroup
423 GROUP BY nodegroup_id;
425 --------------------------------------------------------------------------------
426 -- Node network interfaces
427 --------------------------------------------------------------------------------
429 -- Valid network addressing schemes
430 CREATE TABLE network_types (
431 type text PRIMARY KEY -- Addressing scheme
433 INSERT INTO network_types (type) VALUES ('ipv4');
435 -- Valid network configuration methods
436 CREATE TABLE network_methods (
437 method text PRIMARY KEY -- Configuration method
439 INSERT INTO network_methods (method) VALUES ('static');
440 INSERT INTO network_methods (method) VALUES ('dhcp');
441 INSERT INTO network_methods (method) VALUES ('proxy');
442 INSERT INTO network_methods (method) VALUES ('tap');
443 INSERT INTO network_methods (method) VALUES ('ipmi');
444 INSERT INTO network_methods (method) VALUES ('unknown');
446 -- Node network interfaces
447 CREATE TABLE nodenetworks (
449 nodenetwork_id serial PRIMARY KEY, -- Network interface identifier
450 node_id integer REFERENCES nodes NOT NULL, -- Which node
451 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
452 type text REFERENCES network_types NOT NULL, -- Addressing scheme
453 method text REFERENCES network_methods NOT NULL, -- Configuration method
455 -- Optional, depending on type and method
456 ip text, -- IP address
457 mac text, -- MAC address
458 gateway text, -- Default gateway address
459 network text, -- Network address
460 broadcast text, -- Network broadcast address
461 netmask text, -- Network mask
462 dns1 text, -- Primary DNS server
463 dns2 text, -- Secondary DNS server
464 bwlimit integer, -- Bandwidth limit in bps
465 hostname text -- Hostname of this interface
467 CREATE INDEX nodenetworks_node_id_idx ON nodenetworks (node_id);
469 -- Ordered by primary interface first
470 CREATE VIEW nodenetworks_ordered AS
471 SELECT node_id, nodenetwork_id
473 ORDER BY is_primary DESC;
475 -- Network interfaces on each node
476 CREATE VIEW node_nodenetworks AS
478 array_accum(nodenetwork_id) AS nodenetwork_ids
479 FROM nodenetworks_ordered
482 --------------------------------------------------------------------------------
483 -- Power control units (PCUs)
484 --------------------------------------------------------------------------------
488 pcu_id serial PRIMARY KEY, -- PCU identifier
489 site_id integer REFERENCES sites NOT NULL, -- Site identifier
490 hostname text, -- Hostname, not necessarily unique (multiple logical sites could use the same PCU)
491 ip text NOT NULL, -- IP, not necessarily unique
494 protocol text, -- Protocol, e.g. ssh or https or telnet
495 username text, -- Username, if applicable
496 "password" text, -- Password, if applicable
497 model text, -- Model, e.g. BayTech or iPal
498 notes text -- Random notes
500 CREATE INDEX pcus_site_id_idx ON pcus (site_id);
502 CREATE VIEW site_pcus AS
504 array_accum(pcu_id) AS pcu_ids
508 CREATE TABLE pcu_node (
509 pcu_id integer REFERENCES pcus NOT NULL, -- PCU identifier
510 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
511 port integer NOT NULL, -- Port number
512 PRIMARY KEY (pcu_id, node_id), -- The same node cannot be controlled by different ports
513 UNIQUE (pcu_id, port) -- The same port cannot control multiple nodes
515 CREATE INDEX pcu_node_pcu_id_idx ON pcu_node (pcu_id);
516 CREATE INDEX pcu_node_node_id_idx ON pcu_node (node_id);
518 CREATE VIEW node_pcus AS
520 array_accum(pcu_id) AS pcu_ids,
521 array_accum(port) AS ports
525 CREATE VIEW pcu_nodes AS
527 array_accum(node_id) AS node_ids,
528 array_accum(port) AS ports
532 --------------------------------------------------------------------------------
534 --------------------------------------------------------------------------------
536 CREATE TABLE slice_instantiations (
537 instantiation text PRIMARY KEY
539 INSERT INTO slice_instantiations (instantiation) VALUES ('not-instantiated'); -- Placeholder slice
540 INSERT INTO slice_instantiations (instantiation) VALUES ('plc-instantiated'); -- Instantiated by Node Manager
541 INSERT INTO slice_instantiations (instantiation) VALUES ('delegated'); -- Manually instantiated
544 CREATE TABLE slices (
545 slice_id serial PRIMARY KEY, -- Slice identifier
546 -- xxx temporarily remove the NOT NULL constraint
547 site_id integer REFERENCES sites, -- Site identifier
548 peer_id integer REFERENCES peers, -- on which peer
550 name text NOT NULL, -- Slice name
551 instantiation text REFERENCES slice_instantiations NOT NULL DEFAULT 'plc-instantiated', -- Slice state, e.g. plc-instantiated
552 url text, -- Project URL
553 description text, -- Project description
555 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
557 -- xxx temporarily remove the NOT NULL constraint
558 creator_person_id integer REFERENCES persons, -- Creator
559 created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation date
560 expires timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP + '2 weeks', -- Expiration date
562 is_deleted boolean NOT NULL DEFAULT false
564 CREATE INDEX slices_site_id_idx ON slices (site_id) WHERE is_deleted IS false;
565 CREATE INDEX slices_name_idx ON slices (name) WHERE is_deleted IS false;
568 CREATE TABLE slice_node (
569 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
570 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
571 PRIMARY KEY (slice_id, node_id)
573 CREATE INDEX slice_node_slice_id_idx ON slice_node (slice_id);
574 CREATE INDEX slice_node_node_id_idx ON slice_node (node_id);
576 -- Synonym for slice_node
577 CREATE VIEW slivers AS
578 SELECT * FROM slice_node;
580 -- Nodes in each slice
581 CREATE VIEW slice_nodes AS
583 array_accum(node_id) AS node_ids
587 -- Slices on each node
588 CREATE VIEW node_slices AS
590 array_accum(slice_id) AS slice_ids
594 -- Slices at each site
595 CREATE VIEW site_slices AS
597 array_accum(slice_id) AS slice_ids
599 WHERE is_deleted is false
602 CREATE VIEW peer_slices AS
604 array_accum(slice_id) AS slice_ids
609 CREATE TABLE slice_person (
610 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
611 person_id integer REFERENCES persons NOT NULL, -- Account identifier
612 PRIMARY KEY (slice_id, person_id)
614 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
615 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
617 -- Members of the slice
618 CREATE VIEW slice_persons AS
620 array_accum(person_id) AS person_ids
624 -- Slices of which each person is a member
625 CREATE VIEW person_slices AS
627 array_accum(slice_id) AS slice_ids
631 --------------------------------------------------------------------------------
633 --------------------------------------------------------------------------------
635 -- Slice attribute types
636 CREATE TABLE slice_attribute_types (
637 attribute_type_id serial PRIMARY KEY, -- Attribute type identifier
638 name text UNIQUE NOT NULL, -- Attribute name
639 description text, -- Attribute description
640 min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can set or change this attribute
643 -- Slice/sliver attributes
644 CREATE TABLE slice_attribute (
645 slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
646 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
647 node_id integer REFERENCES nodes, -- Sliver attribute if set
648 attribute_type_id integer REFERENCES slice_attribute_types NOT NULL, -- Attribute type identifier
651 CREATE INDEX slice_attribute_slice_id_idx ON slice_attribute (slice_id);
652 CREATE INDEX slice_attribute_node_id_idx ON slice_attribute (node_id);
654 CREATE VIEW slice_attributes AS
656 array_accum(slice_attribute_id) AS slice_attribute_ids
660 --------------------------------------------------------------------------------
661 -- Authenticated sessions
662 --------------------------------------------------------------------------------
664 -- Authenticated sessions
665 CREATE TABLE sessions (
666 session_id text PRIMARY KEY, -- Session identifier
667 expires timestamp without time zone
670 -- People can have multiple sessions
671 CREATE TABLE person_session (
672 person_id integer REFERENCES persons NOT NULL, -- Account identifier
673 session_id text REFERENCES sessions NOT NULL, -- Session identifier
674 PRIMARY KEY (person_id, session_id),
675 UNIQUE (session_id) -- Sessions are unique
677 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
679 -- Nodes can have only one session
680 CREATE TABLE node_session (
681 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
682 session_id text REFERENCES sessions NOT NULL, -- Session identifier
683 UNIQUE (node_id), -- Nodes can have only one session
684 UNIQUE (session_id) -- Sessions are unique
687 --------------------------------------------------------------------------------
689 --------------------------------------------------------------------------------
691 CREATE TABLE messages (
692 message_id text PRIMARY KEY, -- Message name
693 subject text, -- Message summary
694 template text, -- Message template
695 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
698 --------------------------------------------------------------------------------
700 --------------------------------------------------------------------------------
703 CREATE TABLE event_types (
704 event_type text PRIMARY KEY -- Event type
706 INSERT INTO event_types (event_type) VALUES ('Add');
707 INSERT INTO event_types (event_type) VALUES ('AddTo');
708 INSERT INTO event_types (event_type) VALUES ('Get');
709 INSERT INTO event_types (event_type) VALUES ('Update');
710 INSERT INTO event_types (event_type) VALUES ('Delete');
711 INSERT INTO event_types (event_type) VALUES ('DeleteFrom');
712 INSERT INTO event_types (event_type) VALUES ('Unknown');
715 CREATE TABLE object_types (
716 object_type text PRIMARY KEY -- Object type
718 INSERT INTO object_types (object_type) VALUES ('AddressType');
719 INSERT INTO object_types (object_type) VALUES ('Address');
720 INSERT INTO object_types (object_type) VALUES ('BootState');
721 INSERT INTO object_types (object_type) VALUES ('ConfFile');
722 INSERT INTO object_types (object_type) VALUES ('KeyType');
723 INSERT INTO object_types (object_type) VALUES ('Key');
724 INSERT INTO object_types (object_type) VALUES ('Message');
725 INSERT INTO object_types (object_type) VALUES ('NetworkMethod');
726 INSERT INTO object_types (object_type) VALUES ('NetworkType');
727 INSERT INTO object_types (object_type) VALUES ('Network');
728 INSERT INTO object_types (object_type) VALUES ('NodeGroup');
729 INSERT INTO object_types (object_type) VALUES ('NodeNetwork');
730 INSERT INTO object_types (object_type) VALUES ('Node');
731 INSERT INTO object_types (object_type) VALUES ('PCU');
732 INSERT INTO object_types (object_type) VALUES ('Person');
733 INSERT INTO object_types (object_type) VALUES ('Role');
734 INSERT INTO object_types (object_type) VALUES ('Session');
735 INSERT INTO object_types (object_type) VALUES ('Site');
736 INSERT INTO object_types (object_type) VALUES ('SliceAttributeType');
737 INSERT INTO object_types (object_type) VALUES ('SliceAttribute');
738 INSERT INTO object_types (object_type) VALUES ('Slice');
739 INSERT INTO object_types (object_type) VALUES ('SliceInstantiation');
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,
804 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
805 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
806 COALESCE(person_roles.role_ids, '{}') AS role_ids,
807 COALESCE(person_roles.roles, '{}') AS roles,
808 COALESCE(person_sites.site_ids, '{}') AS site_ids,
809 COALESCE(person_keys.key_ids, '{}') AS key_ids,
810 COALESCE(person_slices.slice_ids, '{}') AS slice_ids
812 LEFT JOIN person_roles USING (person_id)
813 LEFT JOIN person_sites USING (person_id)
814 LEFT JOIN person_keys USING (person_id)
815 LEFT JOIN person_slices USING (person_id);
817 CREATE VIEW view_peers AS
821 peer_slices.slice_ids
823 LEFT JOIN peer_nodes USING (peer_id)
824 LEFT JOIN peer_slices USING (peer_id);
826 CREATE VIEW view_nodes AS
839 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
840 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
841 COALESCE(node_nodenetworks.nodenetwork_ids, '{}') AS nodenetwork_ids,
842 COALESCE(node_nodegroups.nodegroup_ids, '{}') AS nodegroup_ids,
843 COALESCE(node_slices.slice_ids, '{}') AS slice_ids,
844 COALESCE(node_pcus.pcu_ids, '{}') AS pcu_ids,
845 COALESCE(node_pcus.ports, '{}') AS ports,
846 COALESCE(node_conf_files.conf_file_ids, '{}') AS conf_file_ids,
847 node_session.session_id AS session
849 LEFT JOIN node_nodenetworks USING (node_id)
850 LEFT JOIN node_nodegroups USING (node_id)
851 LEFT JOIN node_slices USING (node_id)
852 LEFT JOIN node_pcus USING (node_id)
853 LEFT JOIN node_conf_files USING (node_id)
854 LEFT JOIN node_session USING (node_id);
856 CREATE VIEW view_nodegroups AS
858 nodegroups.nodegroup_id,
860 nodegroups.description,
861 COALESCE(nodegroup_nodes.node_ids, '{}') AS node_ids,
862 COALESCE(nodegroup_conf_files.conf_file_ids, '{}') AS conf_file_ids
864 LEFT JOIN nodegroup_nodes USING (nodegroup_id)
865 LEFT JOIN nodegroup_conf_files USING (nodegroup_id);
867 CREATE VIEW view_conf_files AS
869 conf_files.conf_file_id,
873 conf_files.file_permissions,
874 conf_files.file_owner,
875 conf_files.file_group,
876 conf_files.preinstall_cmd,
877 conf_files.postinstall_cmd,
878 conf_files.error_cmd,
879 conf_files.ignore_cmd_errors,
880 conf_files.always_update,
881 COALESCE(conf_file_nodes.node_ids, '{}') AS node_ids,
882 COALESCE(conf_file_nodegroups.nodegroup_ids, '{}') AS nodegroup_ids
884 LEFT JOIN conf_file_nodes USING (conf_file_id)
885 LEFT JOIN conf_file_nodegroups USING (conf_file_id);
887 CREATE VIEW view_pcus AS
898 COALESCE(pcu_nodes.node_ids, '{}') AS node_ids,
899 COALESCE(pcu_nodes.ports, '{}') AS ports
901 LEFT JOIN pcu_nodes USING (pcu_id);
903 CREATE VIEW view_sites AS
908 sites.abbreviated_name,
916 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
917 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
918 COALESCE(site_persons.person_ids, '{}') AS person_ids,
919 COALESCE(site_nodes.node_ids, '{}') AS node_ids,
920 COALESCE(site_addresses.address_ids, '{}') AS address_ids,
921 COALESCE(site_slices.slice_ids, '{}') AS slice_ids,
922 COALESCE(site_pcus.pcu_ids, '{}') AS pcu_ids
924 LEFT JOIN site_persons USING (site_id)
925 LEFT JOIN site_nodes USING (site_id)
926 LEFT JOIN site_addresses USING (site_id)
927 LEFT JOIN site_slices USING (site_id)
928 LEFT JOIN site_pcus USING (site_id);
930 CREATE VIEW view_addresses AS
932 addresses.address_id,
938 addresses.postalcode,
940 COALESCE(address_address_types.address_type_ids, '{}') AS address_type_ids,
941 COALESCE(address_address_types.address_types, '{}') AS address_types
943 LEFT JOIN address_address_types USING (address_id);
945 CREATE VIEW view_slices AS
951 slices.instantiation,
955 slices.creator_person_id,
957 CAST(date_part('epoch', slices.created) AS bigint) AS created,
958 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
959 COALESCE(slice_nodes.node_ids, '{}') AS node_ids,
960 COALESCE(slice_persons.person_ids, '{}') AS person_ids,
961 COALESCE(slice_attributes.slice_attribute_ids, '{}') AS slice_attribute_ids
963 LEFT JOIN slice_nodes USING (slice_id)
964 LEFT JOIN slice_persons USING (slice_id)
965 LEFT JOIN slice_attributes USING (slice_id);
968 CREATE VIEW view_slice_attributes AS
970 slice_attribute.slice_attribute_id,
971 slice_attribute.slice_id,
972 slice_attribute.node_id,
973 slice_attribute_types.attribute_type_id,
974 slice_attribute_types.name,
975 slice_attribute_types.description,
976 slice_attribute_types.min_role_id,
977 slice_attribute.value
979 INNER JOIN slice_attribute_types USING (attribute_type_id);
981 CREATE VIEW view_sessions AS
984 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
985 person_session.person_id,
988 LEFT JOIN person_session USING (session_id)
989 LEFT JOIN node_session USING (session_id);
991 --------------------------------------------------------------------------------
992 -- Built-in maintenance account and default site
993 --------------------------------------------------------------------------------
996 (first_name, last_name, email, password, enabled)
998 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
1000 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
1001 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
1002 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
1003 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
1006 (login_base, name, abbreviated_name, max_slices)
1008 ('pl', 'PlanetLab Central', 'PLC', 100);