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.27 2006/11/03 20:36:05 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 persons (
35 person_id serial PRIMARY KEY, -- Account identifier
36 email text NOT NULL, -- E-mail address
37 first_name text NOT NULL, -- First name
38 last_name text NOT NULL, -- Last name
39 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
40 enabled boolean NOT NULL DEFAULT false, -- Has been disabled
43 password text NOT NULL, -- Password (md5crypted)
44 verification_key text, -- Reset password key
45 verification_expires timestamp without time zone,
48 title text, -- Honorific
49 phone text, -- Telephone number
50 url text, -- Home page
51 bio text, -- Biography
54 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
55 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
57 CREATE INDEX persons_email_idx ON persons (email) WHERE deleted IS false;
59 --------------------------------------------------------------------------------
61 --------------------------------------------------------------------------------
66 site_id serial PRIMARY KEY, -- Site identifier
67 login_base text NOT NULL, -- Site slice prefix
68 name text NOT NULL, -- Site name
69 abbreviated_name text NOT NULL, -- Site abbreviated name
70 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
71 is_public boolean NOT NULL DEFAULT true, -- Shows up in public lists
72 max_slices integer NOT NULL DEFAULT 0, -- Maximum number of slices
73 max_slivers integer NOT NULL DEFAULT 1000, -- Maximum number of instantiated slivers
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 CREATE INDEX sites_login_base_idx ON sites (login_base) WHERE deleted IS false;
86 -- Account site membership
87 CREATE TABLE person_site (
88 person_id integer REFERENCES persons NOT NULL, -- Account identifier
89 site_id integer REFERENCES sites NOT NULL, -- Site identifier
90 is_primary boolean NOT NULL DEFAULT false, -- Is the primary site for this account
91 PRIMARY KEY (person_id, site_id)
93 CREATE INDEX person_site_person_id_idx ON person_site (person_id);
94 CREATE INDEX person_site_site_id_idx ON person_site (site_id);
96 -- Ordered by primary site first
97 CREATE VIEW person_site_ordered AS
98 SELECT person_id, site_id
100 ORDER BY is_primary DESC;
102 -- Sites that each person is a member of
103 CREATE VIEW person_sites AS
105 array_to_string(array_accum(site_id), ',') AS site_ids
106 FROM person_site_ordered
109 -- Accounts at each site
110 CREATE VIEW site_persons AS
112 array_to_string(array_accum(person_id), ',') AS person_ids
116 --------------------------------------------------------------------------------
118 --------------------------------------------------------------------------------
120 CREATE TABLE address_types (
121 address_type_id serial PRIMARY KEY, -- Address type identifier
122 name text UNIQUE NOT NULL, -- Address type
123 description text -- Address type description
126 INSERT INTO address_types (name) VALUES ('Personal');
127 INSERT INTO address_types (name) VALUES ('Shipping');
128 -- XXX Used to be Site
129 INSERT INTO address_types (name) VALUES ('Billing');
132 CREATE TABLE addresses (
133 address_id serial PRIMARY KEY, -- Address identifier
134 line1 text NOT NULL, -- Address line 1
135 line2 text, -- Address line 2
136 line3 text, -- Address line 3
137 city text NOT NULL, -- City
138 state text NOT NULL, -- State or province
139 postalcode text NOT NULL, -- Postal code
140 country text NOT NULL -- Country
143 -- Each mailing address can be one of several types
144 CREATE TABLE address_address_type (
145 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
146 address_type_id integer REFERENCES address_types NOT NULL, -- Address type
147 PRIMARY KEY (address_id, address_type_id)
149 CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
150 CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);
152 CREATE VIEW address_address_types AS
154 array_to_string(array_accum(address_type_id), ',') AS address_type_ids,
155 array_to_string(array_accum(address_types.name), ',') AS address_types
156 FROM address_address_type
157 LEFT JOIN address_types USING (address_type_id)
160 CREATE TABLE site_address (
161 site_id integer REFERENCES sites NOT NULL, -- Site identifier
162 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
163 PRIMARY KEY (site_id, address_id)
165 CREATE INDEX site_address_site_id_idx ON site_address (site_id);
166 CREATE INDEX site_address_address_id_idx ON site_address (address_id);
168 CREATE VIEW site_addresses AS
170 array_to_string(array_accum(address_id), ',') AS address_ids
174 --------------------------------------------------------------------------------
175 -- Authentication Keys
176 --------------------------------------------------------------------------------
179 CREATE TABLE key_types (
180 key_type text PRIMARY KEY -- Key type
182 INSERT INTO key_types (key_type) VALUES ('ssh');
184 -- Authentication keys
186 key_id serial PRIMARY KEY, -- Key identifier
187 key_type text REFERENCES key_types NOT NULL, -- Key type
188 key text NOT NULL, -- Key material
189 is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
192 -- Account authentication key(s)
193 CREATE TABLE person_key (
194 person_id integer REFERENCES persons NOT NULL, -- Account identifier
195 key_id integer REFERENCES keys NOT NULL, -- Key identifier
196 PRIMARY KEY (person_id, key_id)
198 CREATE INDEX person_key_person_id_idx ON person_key (person_id);
199 CREATE INDEX person_key_key_id_idx ON person_key (key_id);
201 CREATE VIEW person_keys AS
203 array_to_string(array_accum(key_id), ',') AS key_ids
207 --------------------------------------------------------------------------------
209 --------------------------------------------------------------------------------
211 -- Valid account roles
213 role_id integer PRIMARY KEY, -- Role identifier
214 name text UNIQUE NOT NULL -- Role symbolic name
216 INSERT INTO roles (role_id, name) VALUES (10, 'admin');
217 INSERT INTO roles (role_id, name) VALUES (20, 'pi');
218 INSERT INTO roles (role_id, name) VALUES (30, 'user');
219 INSERT INTO roles (role_id, name) VALUES (40, 'tech');
220 INSERT INTO roles (role_id, name) VALUES (1000, 'node');
221 INSERT INTO roles (role_id, name) VALUES (2000, 'anonymous');
222 -- xxx not sure this us useful yet
223 --INSERT INTO roles (role_id, name) VALUES (3000, 'peer');
225 CREATE TABLE person_role (
226 person_id integer REFERENCES persons NOT NULL, -- Account identifier
227 role_id integer REFERENCES roles NOT NULL, -- Role identifier
228 PRIMARY KEY (person_id, role_id)
230 CREATE INDEX person_role_person_id_idx ON person_role (person_id);
233 CREATE VIEW person_roles AS
235 array_to_string(array_accum(role_id), ',') AS role_ids,
236 array_to_string(array_accum(roles.name), ',') AS roles
238 LEFT JOIN roles USING (role_id)
241 --------------------------------------------------------------------------------
243 --------------------------------------------------------------------------------
245 -- Valid node boot states
246 CREATE TABLE boot_states (
247 boot_state text PRIMARY KEY
249 INSERT INTO boot_states (boot_state) VALUES ('boot');
250 INSERT INTO boot_states (boot_state) VALUES ('dbg');
251 INSERT INTO boot_states (boot_state) VALUES ('inst');
252 INSERT INTO boot_states (boot_state) VALUES ('rins');
253 INSERT INTO boot_states (boot_state) VALUES ('rcnf');
254 INSERT INTO boot_states (boot_state) VALUES ('new');
258 peer_id serial PRIMARY KEY, -- identifier
259 peername text NOT NULL, -- free text
260 peer_url text NOT NULL, -- the url of that peer's API
261 person_id integer REFERENCES persons NOT NULL, -- the account we use for logging in
263 deleted boolean NOT NULL DEFAULT false
270 node_id serial PRIMARY KEY, -- Node identifier
271 hostname text NOT NULL, -- Node hostname
272 site_id integer REFERENCES sites, -- At which site (clause NOT NULL removed for foreign_nodes)
273 boot_state text REFERENCES boot_states NOT NULL DEFAULT 'inst', -- Node boot state
274 cached boolean NOT NULL DEFAULT false, -- is this entry cached from a peer ?
275 peer_id integer REFERENCES peers, -- if cached, then from what peer
276 deleted boolean NOT NULL DEFAULT false, -- Is deleted
279 model text, -- Hardware make and model
280 boot_nonce text, -- Random nonce updated by Boot Manager
281 version text, -- Boot CD version string updated by Boot Manager
282 -- XXX Should be key_id integer REFERENCES keys
283 ssh_rsa_key text, -- SSH host key updated by Boot Manager
284 key text, -- Node key generated by API when configuration file is downloaded
287 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
288 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
290 CREATE INDEX nodes_hostname_idx ON nodes (hostname) WHERE deleted IS false;
291 CREATE INDEX nodes_site_id_idx ON nodes (site_id) WHERE deleted IS false;
293 -- Nodes at each site
294 CREATE VIEW site_nodes AS
296 array_to_string(array_accum(node_id), ',') AS node_ids
300 -- Nodes at each peer
301 CREATE VIEW peer_nodes AS
303 array_to_string(array_accum(node_id), ',') AS node_ids
307 CREATE VIEW view_peers AS
312 LEFT JOIN peer_nodes USING (peer_id);
314 --------------------------------------------------------------------------------
316 --------------------------------------------------------------------------------
319 CREATE TABLE nodegroups (
320 nodegroup_id serial PRIMARY KEY, -- Group identifier
321 name text UNIQUE NOT NULL, -- Group name
322 description text -- Group description
325 -- Node group membership
326 CREATE TABLE nodegroup_node (
327 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Group identifier
328 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
329 PRIMARY KEY (nodegroup_id, node_id)
331 CREATE INDEX nodegroup_node_nodegroup_id_idx ON nodegroup_node (nodegroup_id);
332 CREATE INDEX nodegroup_node_node_id_idx ON nodegroup_node (node_id);
334 -- Nodes in each node group
335 CREATE VIEW nodegroup_nodes AS
337 array_to_string(array_accum(node_id), ',') AS node_ids
339 GROUP BY nodegroup_id;
341 -- Node groups that each node is a member of
342 CREATE VIEW node_nodegroups AS
344 array_to_string(array_accum(nodegroup_id), ',') AS nodegroup_ids
348 --------------------------------------------------------------------------------
349 -- Node configuration files
350 --------------------------------------------------------------------------------
352 CREATE TABLE conf_files (
353 conf_file_id serial PRIMARY KEY, -- Configuration file identifier
354 enabled bool NOT NULL DEFAULT true, -- Configuration file is active
355 source text NOT NULL, -- Relative path on the boot server where file can be downloaded
356 dest text NOT NULL, -- Absolute path where file should be installed
357 file_permissions text NOT NULL DEFAULT '0644', -- chmod(1) permissions
358 file_owner text NOT NULL DEFAULT 'root', -- chown(1) owner
359 file_group text NOT NULL DEFAULT 'root', -- chgrp(1) owner
360 preinstall_cmd text, -- Shell command to execute prior to installing
361 postinstall_cmd text, -- Shell command to execute after installing
362 error_cmd text, -- Shell command to execute if any error occurs
363 ignore_cmd_errors bool NOT NULL DEFAULT false, -- Install file anyway even if an error occurs
364 always_update bool NOT NULL DEFAULT false -- Always attempt to install file even if unchanged
367 CREATE TABLE conf_file_node (
368 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
369 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
370 PRIMARY KEY (conf_file_id, node_id)
372 CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
373 CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
375 -- Nodes linked to each configuration file
376 CREATE VIEW conf_file_nodes AS
378 array_to_string(array_accum(node_id), ',') AS node_ids
380 GROUP BY conf_file_id;
382 -- Configuration files linked to each node
383 CREATE VIEW node_conf_files AS
385 array_to_string(array_accum(conf_file_id), ',') AS conf_file_ids
389 CREATE TABLE conf_file_nodegroup (
390 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
391 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Node group identifier
392 PRIMARY KEY (conf_file_id, nodegroup_id)
394 CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
395 CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
397 -- Node groups linked to each configuration file
398 CREATE VIEW conf_file_nodegroups AS
400 array_to_string(array_accum(nodegroup_id), ',') AS nodegroup_ids
401 FROM conf_file_nodegroup
402 GROUP BY conf_file_id;
404 -- Configuration files linked to each node group
405 CREATE VIEW nodegroup_conf_files AS
407 array_to_string(array_accum(conf_file_id), ',') AS conf_file_ids
408 FROM conf_file_nodegroup
409 GROUP BY nodegroup_id;
411 --------------------------------------------------------------------------------
412 -- Node network interfaces
413 --------------------------------------------------------------------------------
415 -- Valid network addressing schemes
416 CREATE TABLE network_types (
417 type text PRIMARY KEY -- Addressing scheme
419 INSERT INTO network_types (type) VALUES ('ipv4');
421 -- Valid network configuration methods
422 CREATE TABLE network_methods (
423 method text PRIMARY KEY -- Configuration method
425 INSERT INTO network_methods (method) VALUES ('static');
426 INSERT INTO network_methods (method) VALUES ('dhcp');
427 INSERT INTO network_methods (method) VALUES ('proxy');
428 INSERT INTO network_methods (method) VALUES ('tap');
429 INSERT INTO network_methods (method) VALUES ('ipmi');
430 INSERT INTO network_methods (method) VALUES ('unknown');
432 -- Node network interfaces
433 CREATE TABLE nodenetworks (
435 nodenetwork_id serial PRIMARY KEY, -- Network interface identifier
436 node_id integer REFERENCES nodes NOT NULL, -- Which node
437 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
438 type text REFERENCES network_types NOT NULL, -- Addressing scheme
439 method text REFERENCES network_methods NOT NULL, -- Configuration method
441 -- Optional, depending on type and method
442 ip text, -- IP address
443 mac text, -- MAC address
444 gateway text, -- Default gateway address
445 network text, -- Network address
446 broadcast text, -- Network broadcast address
447 netmask text, -- Network mask
448 dns1 text, -- Primary DNS server
449 dns2 text, -- Secondary DNS server
450 bwlimit integer, -- Bandwidth limit in bps
451 hostname text -- Hostname of this interface
453 CREATE INDEX nodenetworks_node_id_idx ON nodenetworks (node_id);
455 -- Ordered by primary interface first
456 CREATE VIEW nodenetworks_ordered AS
457 SELECT node_id, nodenetwork_id
459 ORDER BY is_primary DESC;
461 -- Network interfaces on each node
462 CREATE VIEW node_nodenetworks AS
464 array_to_string(array_accum(nodenetwork_id), ',') AS nodenetwork_ids
465 FROM nodenetworks_ordered
468 --------------------------------------------------------------------------------
469 -- Power control units (PCUs)
470 --------------------------------------------------------------------------------
474 pcu_id serial PRIMARY KEY, -- PCU identifier
475 site_id integer REFERENCES sites NOT NULL, -- Site identifier
476 hostname text, -- Hostname, not necessarily unique (multiple logical sites could use the same PCU)
477 ip text NOT NULL, -- IP, not necessarily unique
480 protocol text, -- Protocol, e.g. ssh or https or telnet
481 username text, -- Username, if applicable
482 "password" text, -- Password, if applicable
483 model text, -- Model, e.g. BayTech or iPal
484 notes text -- Random notes
486 CREATE INDEX pcus_site_id_idx ON pcus (site_id);
488 CREATE VIEW site_pcus AS
490 array_to_string(array_accum(pcu_id), ',') AS pcu_ids
494 CREATE TABLE pcu_node (
495 pcu_id integer REFERENCES pcus NOT NULL, -- PCU identifier
496 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
497 port integer NOT NULL, -- Port number
498 PRIMARY KEY (pcu_id, node_id), -- The same node cannot be controlled by different ports
499 UNIQUE (pcu_id, port) -- The same port cannot control multiple nodes
501 CREATE INDEX pcu_node_pcu_id_idx ON pcu_node (pcu_id);
502 CREATE INDEX pcu_node_node_id_idx ON pcu_node (node_id);
504 CREATE VIEW node_pcus AS
506 array_to_string(array_accum(pcu_id), ',') AS pcu_ids,
507 array_to_string(array_accum(port), ',') AS ports
511 CREATE VIEW pcu_nodes AS
513 array_to_string(array_accum(node_id), ',') AS node_ids,
514 array_to_string(array_accum(port), ',') AS ports
518 --------------------------------------------------------------------------------
520 --------------------------------------------------------------------------------
522 CREATE TABLE slice_instantiations (
523 instantiation text PRIMARY KEY
525 INSERT INTO slice_instantiations (instantiation) VALUES ('not-instantiated'); -- Placeholder slice
526 INSERT INTO slice_instantiations (instantiation) VALUES ('plc-instantiated'); -- Instantiated by Node Manager
527 INSERT INTO slice_instantiations (instantiation) VALUES ('delegated'); -- Manually instantiated
530 CREATE TABLE slices (
531 slice_id serial PRIMARY KEY, -- Slice identifier
532 site_id integer REFERENCES sites NOT NULL, -- Site identifier
533 name text NOT NULL, -- Slice name
534 instantiation text REFERENCES slice_instantiations NOT NULL DEFAULT 'plc-instantiated', -- Slice state, e.g. plc-instantiated
535 url text, -- Project URL
536 description text, -- Project description
538 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
540 creator_person_id integer REFERENCES persons NOT NULL, -- Creator
541 created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation date
542 expires timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP + '2 weeks', -- Expiration date
544 is_deleted boolean NOT NULL DEFAULT false
546 CREATE INDEX slices_site_id_idx ON slices (site_id) WHERE is_deleted IS false;
547 CREATE INDEX slices_name_idx ON slices (name) WHERE is_deleted IS false;
550 CREATE TABLE slice_node (
551 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
552 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
553 PRIMARY KEY (slice_id, node_id)
555 CREATE INDEX slice_node_slice_id_idx ON slice_node (slice_id);
556 CREATE INDEX slice_node_node_id_idx ON slice_node (node_id);
558 -- Synonym for slice_node
559 CREATE VIEW slivers AS
560 SELECT * FROM slice_node;
562 -- Nodes in each slice
563 CREATE VIEW slice_nodes AS
565 array_to_string(array_accum(node_id), ',') AS node_ids
569 -- Slices on each node
570 CREATE VIEW node_slices AS
572 array_to_string(array_accum(slice_id), ',') AS slice_ids
576 -- Slices at each site
577 CREATE VIEW site_slices AS
579 array_to_string(array_accum(slice_id), ',') AS slice_ids
584 CREATE TABLE slice_person (
585 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
586 person_id integer REFERENCES persons NOT NULL, -- Account identifier
587 PRIMARY KEY (slice_id, person_id)
589 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
590 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
592 -- Members of the slice
593 CREATE VIEW slice_persons AS
595 array_to_string(array_accum(person_id), ',') AS person_ids
599 -- Slices of which each person is a member
600 CREATE VIEW person_slices AS
602 array_to_string(array_accum(slice_id), ',') AS slice_ids
606 --------------------------------------------------------------------------------
608 --------------------------------------------------------------------------------
610 -- Slice attribute types
611 CREATE TABLE slice_attribute_types (
612 attribute_type_id serial PRIMARY KEY, -- Attribute type identifier
613 name text UNIQUE NOT NULL, -- Attribute name
614 description text, -- Attribute description
615 min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can set or change this attribute
618 -- Slice/sliver attributes
619 CREATE TABLE slice_attribute (
620 slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
621 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
622 node_id integer REFERENCES nodes, -- Sliver attribute if set
623 attribute_type_id integer REFERENCES slice_attribute_types NOT NULL, -- Attribute type identifier
626 CREATE INDEX slice_attribute_slice_id_idx ON slice_attribute (slice_id);
627 CREATE INDEX slice_attribute_node_id_idx ON slice_attribute (node_id);
629 CREATE VIEW slice_attributes AS
631 array_to_string(array_accum(slice_attribute_id), ',') AS slice_attribute_ids
635 --------------------------------------------------------------------------------
636 -- Authenticated sessions
637 --------------------------------------------------------------------------------
639 -- Authenticated sessions
640 CREATE TABLE sessions (
641 session_id text PRIMARY KEY, -- Session identifier
642 expires timestamp without time zone
645 -- People can have multiple sessions
646 CREATE TABLE person_session (
647 person_id integer REFERENCES persons NOT NULL, -- Account identifier
648 session_id text REFERENCES sessions NOT NULL, -- Session identifier
649 PRIMARY KEY (person_id, session_id),
650 UNIQUE (session_id) -- Sessions are unique
652 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
654 -- Nodes can have only one session
655 CREATE TABLE node_session (
656 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
657 session_id text REFERENCES sessions NOT NULL, -- Session identifier
658 UNIQUE (node_id), -- Nodes can have only one session
659 UNIQUE (session_id) -- Sessions are unique
662 --------------------------------------------------------------------------------
664 --------------------------------------------------------------------------------
666 CREATE TABLE messages (
667 message_id text PRIMARY KEY, -- Message name
668 template text, -- Message template
669 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
672 --------------------------------------------------------------------------------
674 --------------------------------------------------------------------------------
677 CREATE TABLE event_types (
678 event_type text PRIMARY KEY -- Event type
680 INSERT INTO event_types (event_type) VALUES ('Add');
681 INSERT INTO event_types (event_type) VALUES ('AddTo');
682 INSERT INTO event_types (event_type) VALUES ('Get');
683 INSERT INTO event_types (event_type) VALUES ('Update');
684 INSERT INTO event_types (event_type) VALUES ('Delete');
685 INSERT INTO event_types (event_type) VALUES ('DeleteFrom');
686 INSERT INTO event_types (event_type) VALUES ('Unknown');
689 CREATE TABLE object_types (
690 object_type text PRIMARY KEY -- Object type
692 INSERT INTO object_types (object_type) VALUES ('AddressType');
693 INSERT INTO object_types (object_type) VALUES ('Address');
694 INSERT INTO object_types (object_type) VALUES ('BootState');
695 INSERT INTO object_types (object_type) VALUES ('ConfFile');
696 INSERT INTO object_types (object_type) VALUES ('KeyType');
697 INSERT INTO object_types (object_type) VALUES ('Key');
698 INSERT INTO object_types (object_type) VALUES ('NetworkMethod');
699 INSERT INTO object_types (object_type) VALUES ('NetworkType');
700 INSERT INTO object_types (object_type) VALUES ('Network');
701 INSERT INTO object_types (object_type) VALUES ('NodeGroup');
702 INSERT INTO object_types (object_type) VALUES ('NodeNetwork');
703 INSERT INTO object_types (object_type) VALUES ('Node');
704 INSERT INTO object_types (object_type) VALUES ('PCU');
705 INSERT INTO object_types (object_type) VALUES ('Person');
706 INSERT INTO object_types (object_type) VALUES ('Role');
707 INSERT INTO object_types (object_type) VALUES ('Session');
708 INSERT INTO object_types (object_type) VALUES ('Site');
709 INSERT INTO object_types (object_type) VALUES ('SliceAttributeType');
710 INSERT INTO object_types (object_type) VALUES ('SliceAttribute');
711 INSERT INTO object_types (object_type) VALUES ('Slice');
712 INSERT INTO object_types (object_type) VALUES ('Unknown');
715 CREATE TABLE events (
716 event_id serial PRIMARY KEY, -- Event identifier
717 person_id integer REFERENCES persons, -- Person responsible for event, if any
718 node_id integer REFERENCES nodes, -- Node responsible for event, if any
719 event_type text REFERENCES event_types NOT NULL DEFAULT 'Unknown', -- Event type
720 object_type text REFERENCES object_types NOT NULL DEFAULT 'Unknown', -- Object type associated with event
721 fault_code integer NOT NULL DEFAULT 0, -- Did this event result in error
722 call text NOT NULL, -- Call responsible for this event
723 runtime float, -- Event run time
724 time timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP -- Event timestamp
728 CREATE TABLE event_object (
729 event_id integer REFERENCES events NOT NULL, -- Event identifier
730 object_id integer NOT NULL -- Object identifier
732 CREATE INDEX event_object_event_id_idx ON event_object (event_id);
733 CREATE INDEX event_object_object_id_idx ON event_object (object_id);
735 CREATE VIEW event_objects AS
737 array_to_string(array_accum(object_id), ',') AS object_ids
741 --------------------------------------------------------------------------------
743 --------------------------------------------------------------------------------
745 CREATE VIEW view_events AS
750 event_objects.object_ids,
756 CAST(date_part('epoch', events.time) AS bigint) AS time
758 LEFT JOIN event_objects USING (event_id);
760 CREATE VIEW view_persons AS
769 persons.verification_key,
770 persons.verification_expires,
775 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
776 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
777 person_roles.role_ids, person_roles.roles,
778 person_sites.site_ids,
780 person_slices.slice_ids
782 LEFT JOIN person_roles USING (person_id)
783 LEFT JOIN person_sites USING (person_id)
784 LEFT JOIN person_keys USING (person_id)
785 LEFT JOIN person_slices USING (person_id);
787 CREATE VIEW view_nodes AS
798 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
799 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
800 node_nodenetworks.nodenetwork_ids,
801 node_nodegroups.nodegroup_ids,
802 node_slices.slice_ids,
805 node_conf_files.conf_file_ids,
806 node_session.session_id AS session,
809 LEFT JOIN node_nodenetworks USING (node_id)
810 LEFT JOIN node_nodegroups USING (node_id)
811 LEFT JOIN node_slices USING (node_id)
812 LEFT JOIN node_pcus USING (node_id)
813 LEFT JOIN node_conf_files USING (node_id)
814 LEFT JOIN node_session USING (node_id)
815 WHERE nodes.cached=False;
817 CREATE VIEW view_foreign_nodes AS
825 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
826 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
827 node_slices.slice_ids,
830 LEFT JOIN node_slices USING (node_id)
831 WHERE nodes.cached=True AND nodes.deleted=False;
833 CREATE VIEW view_nodegroups AS
835 nodegroups.nodegroup_id,
837 nodegroups.description,
838 nodegroup_nodes.node_ids,
839 nodegroup_conf_files.conf_file_ids
841 LEFT JOIN nodegroup_nodes USING (nodegroup_id)
842 LEFT JOIN nodegroup_conf_files USING (nodegroup_id);
844 CREATE VIEW view_conf_files AS
846 conf_files.conf_file_id,
850 conf_files.file_permissions,
851 conf_files.file_owner,
852 conf_files.file_group,
853 conf_files.preinstall_cmd,
854 conf_files.postinstall_cmd,
855 conf_files.error_cmd,
856 conf_files.ignore_cmd_errors,
857 conf_files.always_update,
858 conf_file_nodes.node_ids,
859 conf_file_nodegroups.nodegroup_ids
861 LEFT JOIN conf_file_nodes USING (conf_file_id)
862 LEFT JOIN conf_file_nodegroups USING (conf_file_id);
864 CREATE VIEW view_pcus AS
878 LEFT JOIN pcu_nodes USING (pcu_id);
880 CREATE VIEW view_sites AS
885 sites.abbreviated_name,
893 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
894 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
895 site_persons.person_ids,
897 site_addresses.address_ids,
898 site_slices.slice_ids,
901 LEFT JOIN site_persons USING (site_id)
902 LEFT JOIN site_nodes USING (site_id)
903 LEFT JOIN site_addresses USING (site_id)
904 LEFT JOIN site_slices USING (site_id)
905 LEFT JOIN site_pcus USING (site_id);
907 CREATE VIEW view_addresses AS
909 addresses.address_id,
915 addresses.postalcode,
917 address_address_types.address_type_ids,
918 address_address_types.address_types
920 LEFT JOIN address_address_types USING (address_id);
922 CREATE VIEW view_slices AS
927 slices.instantiation,
931 slices.creator_person_id,
933 CAST(date_part('epoch', slices.created) AS bigint) AS created,
934 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
935 slice_nodes.node_ids,
936 slice_persons.person_ids,
937 slice_attributes.slice_attribute_ids
939 LEFT JOIN slice_nodes USING (slice_id)
940 LEFT JOIN slice_persons USING (slice_id)
941 LEFT JOIN slice_attributes USING (slice_id);
943 CREATE VIEW view_slice_attributes AS
945 slice_attribute.slice_attribute_id,
946 slice_attribute.slice_id,
947 slice_attribute.node_id,
948 slice_attribute_types.attribute_type_id,
949 slice_attribute_types.name,
950 slice_attribute_types.description,
951 slice_attribute_types.min_role_id,
952 slice_attribute.value
954 INNER JOIN slice_attribute_types USING (attribute_type_id);
956 CREATE VIEW view_sessions AS
959 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
960 person_session.person_id,
963 LEFT JOIN person_session USING (session_id)
964 LEFT JOIN node_session USING (session_id);
966 --------------------------------------------------------------------------------
967 -- Built-in maintenance account and default site
968 --------------------------------------------------------------------------------
971 (first_name, last_name, email, password, enabled)
973 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
975 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
976 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
977 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
978 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
981 (login_base, name, abbreviated_name, max_slices)
983 ('pl', 'PlanetLab Central', 'PLC', 100);
985 -- federation stuff starting here
987 --CREATE TABLE foreign_nodes (
988 -- foreign_node_id serial PRIMARY KEY, -- identifier
989 -- hostname text NOT NULL,
990 -- boot_state text NOT NULL,
991 -- peer_id integer REFERENCES peers NOT NULL,
993 -- deleted boolean NOT NULL DEFAULT false
996 --CREATE VIEW peer_foreign_nodes AS
998 --array_to_string(array_accum(foreign_node_id), ',') AS foreign_node_ids