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.3 2006/10/02 15:19:35 mlhuang 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_key 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_key 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_key ON person_site (person_id);
94 CREATE INDEX person_site_site_id_key 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 --------------------------------------------------------------------------------
121 CREATE TABLE addresses (
122 address_id serial PRIMARY KEY, -- Address identifier
123 address_type text, -- Address type, e.g. shipping or billing
124 line1 text NOT NULL, -- Address line 1
125 line2 text, -- Address line 2
126 line3 text, -- Address line 3
127 city text NOT NULL, -- City
128 state text NOT NULL, -- State or province
129 postalcode text NOT NULL, -- Postal code
130 country text NOT NULL -- Country
133 -- Site mailing addresses
134 CREATE TABLE site_address (
135 site_id integer REFERENCES sites NOT NULL, -- Account identifier
136 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
137 PRIMARY KEY (site_id, address_id)
139 CREATE INDEX site_address_site_id_key ON site_address (site_id);
140 CREATE INDEX site_address_address_id_key ON site_address (address_id);
142 CREATE VIEW site_addresses AS
144 array_to_string(array_accum(address_id), ',') AS address_ids
148 --------------------------------------------------------------------------------
149 -- Authentication Keys
150 --------------------------------------------------------------------------------
153 CREATE TABLE key_types (
154 key_type text PRIMARY KEY -- Key type
156 INSERT INTO key_types (key_type) VALUES ('ssh');
158 -- Authentication keys
160 key_id serial PRIMARY KEY, -- Key identifier
161 key_type text REFERENCES key_types NOT NULL, -- Key type
162 key text NOT NULL, -- Key material
163 is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
166 -- Account authentication key(s)
167 CREATE TABLE person_key (
168 person_id integer REFERENCES persons NOT NULL, -- Account identifier
169 key_id integer REFERENCES keys NOT NULL, -- Key identifier
170 is_primary boolean NOT NULL DEFAULT false, -- Is the primary key for this account
171 PRIMARY KEY (person_id, key_id)
173 CREATE INDEX person_key_person_id_key ON person_key (person_id);
174 CREATE INDEX person_key_key_id_key ON person_key (key_id);
176 CREATE VIEW person_keys AS
178 array_to_string(array_accum(key_id), ',') AS key_ids
182 --------------------------------------------------------------------------------
184 --------------------------------------------------------------------------------
186 -- Valid account roles
188 role_id integer PRIMARY KEY, -- Role identifier
189 name text UNIQUE NOT NULL -- Role symbolic name
191 INSERT INTO roles (role_id, name) VALUES (10, 'admin');
192 INSERT INTO roles (role_id, name) VALUES (20, 'pi');
193 INSERT INTO roles (role_id, name) VALUES (30, 'user');
194 INSERT INTO roles (role_id, name) VALUES (40, 'tech');
195 INSERT INTO roles (role_id, name) VALUES (1000, 'node');
196 INSERT INTO roles (role_id, name) VALUES (2000, 'anonymous');
198 CREATE TABLE person_role (
199 person_id integer REFERENCES persons NOT NULL, -- Account identifier
200 role_id integer REFERENCES roles NOT NULL, -- Role identifier
201 PRIMARY KEY (person_id, role_id)
203 CREATE INDEX person_role_person_id_key ON person_role (person_id);
206 CREATE VIEW person_roles AS
208 array_to_string(array_accum(role_id), ',') AS role_ids,
209 array_to_string(array_accum(roles.name), ',') AS roles
211 LEFT JOIN roles USING (role_id)
214 --------------------------------------------------------------------------------
216 --------------------------------------------------------------------------------
218 -- Valid node boot states
219 CREATE TABLE boot_states (
220 boot_state text PRIMARY KEY
222 INSERT INTO boot_states (boot_state) VALUES ('boot');
223 INSERT INTO boot_states (boot_state) VALUES ('dbg');
224 INSERT INTO boot_states (boot_state) VALUES ('inst');
225 INSERT INTO boot_states (boot_state) VALUES ('rins');
226 INSERT INTO boot_states (boot_state) VALUES ('rcnf');
227 INSERT INTO boot_states (boot_state) VALUES ('new');
232 node_id serial PRIMARY KEY, -- Node identifier
233 hostname text NOT NULL, -- Node hostname
234 site_id integer REFERENCES sites NOT NULL, -- At which site
235 boot_state text REFERENCES boot_states NOT NULL, -- Node boot state
236 deleted boolean NOT NULL DEFAULT false, -- Is deleted
239 model text, -- Hardware make and model
240 boot_nonce text, -- Random nonce updated by Boot Manager
241 version text, -- Boot CD version string updated by Boot Manager
242 -- XXX Should be key_id integer REFERENCES keys
243 ssh_rsa_key text, -- SSH host key updated by Boot Manager
244 key text, -- Node key generated by API when configuration file is downloaded
245 session text, -- Session key generated by PLC when Boot Manager authenticates
248 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
249 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
251 CREATE INDEX nodes_hostname_key ON nodes (hostname) WHERE deleted IS false;
252 CREATE INDEX nodes_site_id_key ON nodes (site_id) WHERE deleted IS false;
254 -- Nodes at each site
255 CREATE VIEW site_nodes AS
257 array_to_string(array_accum(node_id), ',') AS node_ids
261 --------------------------------------------------------------------------------
263 --------------------------------------------------------------------------------
266 CREATE TABLE nodegroups (
267 nodegroup_id serial PRIMARY KEY, -- Group identifier
268 name text UNIQUE NOT NULL, -- Group name
269 description text -- Group description
272 -- Node group membership
273 CREATE TABLE nodegroup_node (
274 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Group identifier
275 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
276 PRIMARY KEY (nodegroup_id, node_id)
278 CREATE INDEX nodegroup_node_nodegroup_id_key ON nodegroup_node (nodegroup_id);
279 CREATE INDEX nodegroup_node_node_id_key ON nodegroup_node (node_id);
281 -- Nodes in each node gruop
282 CREATE VIEW nodegroup_nodes AS
284 array_to_string(array_accum(node_id), ',') AS node_ids
286 GROUP BY nodegroup_id;
288 -- Node groups that each node is a member of
289 CREATE VIEW node_nodegroups AS
291 array_to_string(array_accum(nodegroup_id), ',') AS nodegroup_ids
295 --------------------------------------------------------------------------------
296 -- Node network interfaces
297 --------------------------------------------------------------------------------
299 -- Valid network addressing schemes
300 CREATE TABLE nodenetwork_types (
301 type text PRIMARY KEY -- Addressing scheme
303 INSERT INTO nodenetwork_types (type) VALUES ('ipv4');
304 INSERT INTO nodenetwork_types (type) VALUES ('ipv6');
306 -- Valid network configuration methods
307 CREATE TABLE nodenetwork_methods (
308 method text PRIMARY KEY -- Configuration method
310 INSERT INTO nodenetwork_methods (method) VALUES ('static');
311 INSERT INTO nodenetwork_methods (method) VALUES ('dhcp');
312 INSERT INTO nodenetwork_methods (method) VALUES ('proxy');
313 INSERT INTO nodenetwork_methods (method) VALUES ('tap');
314 INSERT INTO nodenetwork_methods (method) VALUES ('ipmi');
315 INSERT INTO nodenetwork_methods (method) VALUES ('unknown');
317 -- Node network interfaces
318 CREATE TABLE nodenetworks (
320 nodenetwork_id serial PRIMARY KEY, -- Network interface identifier
321 node_id integer REFERENCES nodes NOT NULL, -- Which node
322 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
323 type text REFERENCES nodenetwork_types NOT NULL, -- Addressing scheme
324 method text REFERENCES nodenetwork_methods NOT NULL, -- Configuration method
326 -- Optional, depending on type and method
327 ip text, -- IP address
328 mac text, -- MAC address
329 gateway text, -- Default gateway address
330 network text, -- Network address
331 broadcast text, -- Network broadcast address
332 netmask text, -- Network mask
333 dns1 text, -- Primary DNS server
334 dns2 text, -- Secondary DNS server
335 bwlimit integer, -- Bandwidth limit in bps
336 hostname text -- Hostname of this interface
338 CREATE INDEX nodenetworks_node_id_key ON nodenetworks (node_id);
340 -- Ordered by primary interface first
341 CREATE VIEW nodenetworks_ordered AS
342 SELECT node_id, nodenetwork_id
344 ORDER BY is_primary DESC;
346 -- Network interfaces on each node
347 CREATE VIEW node_nodenetworks AS
349 array_to_string(array_accum(nodenetwork_id), ',') AS nodenetwork_ids
350 FROM nodenetworks_ordered
353 --------------------------------------------------------------------------------
355 --------------------------------------------------------------------------------
357 CREATE TABLE slice_instantiations (
358 instantiation text PRIMARY KEY
360 INSERT INTO slice_instantiations (instantiation) VALUES ('not-instantiated'); -- Placeholder slice
361 INSERT INTO slice_instantiations (instantiation) VALUES ('plc-instantiated'); -- Instantiated by Node Manager
362 INSERT INTO slice_instantiations (instantiation) VALUES ('delegated'); -- Manually instantiated
365 CREATE TABLE slices (
366 slice_id serial PRIMARY KEY, -- Slice identifier
367 site_id integer REFERENCES sites NOT NULL, -- Site identifier
368 name text NOT NULL, -- Slice name
369 instantiation text REFERENCES slice_instantiations NOT NULL DEFAULT 'plc-instantiated', -- Slice state, e.g. plc-instantiated
370 url text, -- Project URL
371 description text, -- Project description
373 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
375 creator_person_id integer REFERENCES persons NOT NULL, -- Creator
376 created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation date
377 expires timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP + '2 weeks', -- Expiration date
379 is_deleted boolean NOT NULL DEFAULT false
381 CREATE INDEX slices_site_id_key ON slices (site_id) WHERE is_deleted IS false;
382 CREATE INDEX slices_name_key ON slices (name) WHERE is_deleted IS false;
385 CREATE TABLE slice_node (
386 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
387 node_id integer REFERENCES nodes NOT NULL -- Node identifier
389 CREATE INDEX slice_node_slice_id_key ON slice_node (slice_id);
390 CREATE INDEX slice_node_node_id_key ON slice_node (node_id);
392 -- Synonym for slice_node
393 CREATE VIEW slivers AS
394 SELECT * FROM slice_node;
396 -- Nodes in each slice
397 CREATE VIEW slice_nodes AS
399 array_to_string(array_accum(node_id), ',') AS node_ids
403 -- Slices on each node
404 CREATE VIEW node_slices AS
406 array_to_string(array_accum(slice_id), ',') AS slice_ids
410 -- Slices at each site
411 CREATE VIEW site_slices AS
413 array_to_string(array_accum(slice_id), ',') AS slice_ids
418 CREATE TABLE slice_person (
419 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
420 person_id integer REFERENCES persons NOT NULL, -- Account identifier
421 PRIMARY KEY (slice_id, person_id)
423 CREATE INDEX slice_person_slice_id_key ON slice_person (slice_id);
424 CREATE INDEX slice_person_person_id_key ON slice_person (person_id);
426 -- Members of the slice
427 CREATE VIEW slice_persons AS
429 array_to_string(array_accum(person_id), ',') AS person_ids
433 -- Slices of which each person is a member
434 CREATE VIEW person_slices AS
436 array_to_string(array_accum(slice_id), ',') AS slice_ids
440 --------------------------------------------------------------------------------
442 --------------------------------------------------------------------------------
444 -- Generic attribute types
445 CREATE TABLE attributes (
446 attribute_id serial PRIMARY KEY, -- Attribute type identifier
447 name text UNIQUE NOT NULL, -- Attribute name
448 description text, -- Attribute description
449 min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can set or change this attribute
452 -- Slice/sliver attributes
453 CREATE TABLE slice_attribute (
454 slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
455 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
456 node_id integer REFERENCES nodes, -- Sliver attribute if set
457 attribute_id integer REFERENCES attributes NOT NULL, -- Attribute identifier
460 CREATE INDEX slice_attribute_slice_id_key ON slice_attribute (slice_id);
461 CREATE INDEX slice_attribute_node_id_key ON slice_attribute (node_id);
463 CREATE VIEW slice_attributes AS
465 array_to_string(array_accum(slice_attribute_id), ',') AS slice_attribute_ids
470 CREATE TABLE node_attribute (
471 node_attribute_id serial PRIMARY KEY, -- Node attribute identifier
472 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
473 attribute_id integer REFERENCES attributes NOT NULL, -- Attribute identifier
476 CREATE INDEX node_attribute_node_id_key ON node_attribute (node_id);
478 CREATE VIEW node_attributes AS
480 array_to_string(array_accum(node_attribute_id), ',') AS node_attribute_ids
484 --------------------------------------------------------------------------------
486 --------------------------------------------------------------------------------
488 CREATE VIEW view_persons AS
497 persons.verification_key,
498 persons.verification_expires,
503 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
504 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
505 person_roles.role_ids, person_roles.roles,
506 person_sites.site_ids,
508 person_slices.slice_ids
510 LEFT JOIN person_roles USING (person_id)
511 LEFT JOIN person_sites USING (person_id)
512 LEFT JOIN person_keys USING (person_id)
513 LEFT JOIN person_slices USING (person_id);
515 CREATE VIEW view_nodes AS
528 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
529 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
530 node_nodenetworks.nodenetwork_ids,
531 node_nodegroups.nodegroup_ids,
532 node_slices.slice_ids
534 LEFT JOIN node_nodenetworks USING (node_id)
535 LEFT JOIN node_nodegroups USING (node_id)
536 LEFT JOIN node_slices USING (node_id);
538 CREATE VIEW view_node_attributes AS
540 node_attribute.node_attribute_id,
541 node_attribute.node_id,
542 attributes.attribute_id,
544 attributes.description,
545 attributes.min_role_id,
548 INNER JOIN attributes USING (attribute_id);
550 CREATE VIEW view_nodegroups AS
552 nodegroups.nodegroup_id,
554 nodegroups.description,
555 nodegroup_nodes.node_ids
557 LEFT JOIN nodegroup_nodes USING (nodegroup_id);
559 CREATE VIEW view_sites AS
564 sites.abbreviated_name,
572 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
573 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
574 site_persons.person_ids,
576 site_addresses.address_ids,
577 site_slices.slice_ids
579 LEFT JOIN site_persons USING (site_id)
580 LEFT JOIN site_nodes USING (site_id)
581 LEFT JOIN site_addresses USING (site_id)
582 LEFT JOIN site_slices USING (site_id);
584 CREATE VIEW view_addresses AS
586 addresses.address_id,
587 addresses.address_type,
593 addresses.postalcode,
597 LEFT JOIN site_address USING (address_id);
599 CREATE VIEW view_slices AS
604 slices.instantiation,
608 slices.creator_person_id,
610 CAST(date_part('epoch', slices.created) AS bigint) AS created,
611 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
612 slice_nodes.node_ids,
613 slice_persons.person_ids,
614 slice_attributes.slice_attribute_ids
616 LEFT JOIN slice_nodes USING (slice_id)
617 LEFT JOIN slice_persons USING (slice_id)
618 LEFT JOIN slice_attributes USING (slice_id);
620 CREATE VIEW view_slice_attributes AS
622 slice_attribute.slice_attribute_id,
623 slice_attribute.slice_id,
624 slice_attribute.node_id,
625 attributes.attribute_id,
627 attributes.description,
628 attributes.min_role_id,
629 slice_attribute.value
631 INNER JOIN attributes USING (attribute_id);
633 --------------------------------------------------------------------------------
634 -- Built-in maintenance account and default site
635 --------------------------------------------------------------------------------
638 (first_name, last_name, email, password, enabled)
640 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
642 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
643 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
644 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
645 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
648 (login_base, name, abbreviated_name, max_slices)
650 ('pl', 'PlanetLab Central', 'PLC', 100);