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.2 2006/09/25 18:34:48 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);
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);
86 -- Account site membership
87 CREATE TABLE person_site (
88 person_id integer REFERENCES persons, -- Account identifier
89 site_id integer REFERENCES sites, -- 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, -- Account identifier
136 address_id integer REFERENCES addresses, -- 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, -- 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, -- Account identifier
169 key_id integer REFERENCES keys, -- 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, -- Account identifier
200 role_id integer REFERENCES roles, -- 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, -- At which site
235 boot_state text REFERENCES boot_states, -- 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);
252 CREATE INDEX nodes_site_id_key ON nodes (site_id);
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, -- Group identifier
275 node_id integer REFERENCES nodes, -- 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, -- Which node
322 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
323 type text REFERENCES nodenetwork_types, -- Addressing scheme
324 method text REFERENCES nodenetwork_methods, -- 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, -- Site identifier
368 name text NOT NULL, -- Slice name
369 instantiation text REFERENCES slice_instantiations 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, -- 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);
382 CREATE INDEX slices_name_key ON slices (name);
385 CREATE TABLE slice_node (
386 slice_id integer REFERENCES slices, -- Slice identifier
387 node_id integer REFERENCES nodes -- 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, -- Slice identifier
420 person_id integer REFERENCES persons, -- 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 CREATE TABLE attributes (
445 attribute_id serial PRIMARY KEY, -- Attribute identifier
446 name text UNIQUE NOT NULL, -- Attribute name
447 description text, -- Attribute description
448 min_role_id integer REFERENCES roles -- Minimum (least powerful) role that can set or change this attribute
451 -- Slice/sliver attributes
452 CREATE TABLE slice_attribute (
453 slice_id integer REFERENCES slices, -- Slice identifier
454 attribute_id integer REFERENCES attributes, -- Attribute identifier
455 node_id integer, -- Sliver attribute if set
457 PRIMARY KEY (slice_id, attribute_id, node_id)
459 CREATE INDEX slice_attribute_slice_id_key ON slice_attribute (slice_id);
460 CREATE INDEX slice_attribute_node_id_key ON slice_attribute (node_id);
462 CREATE VIEW slice_attributes AS
464 array_to_string(array_accum(attribute_id), ',') AS attribute_ids
466 WHERE node_id IS NULL
469 -- No sliver_attributes view since it by definition requires a conditional on node_id
471 --------------------------------------------------------------------------------
473 --------------------------------------------------------------------------------
475 CREATE VIEW view_persons AS
484 persons.verification_key,
485 persons.verification_expires,
490 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
491 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
492 person_roles.role_ids, person_roles.roles,
493 person_sites.site_ids,
495 person_slices.slice_ids
497 LEFT JOIN person_roles USING (person_id)
498 LEFT JOIN person_sites USING (person_id)
499 LEFT JOIN person_keys USING (person_id)
500 LEFT JOIN person_slices USING (person_id);
502 CREATE VIEW view_nodes AS
515 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
516 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
517 node_nodenetworks.nodenetwork_ids,
518 node_nodegroups.nodegroup_ids,
519 node_slices.slice_ids
521 LEFT JOIN node_nodenetworks USING (node_id)
522 LEFT JOIN node_nodegroups USING (node_id)
523 LEFT JOIN node_slices USING (node_id);
525 CREATE VIEW view_nodegroups AS
527 nodegroups.nodegroup_id,
529 nodegroups.description,
530 nodegroup_nodes.node_ids
532 LEFT JOIN nodegroup_nodes USING (nodegroup_id);
534 CREATE VIEW view_sites AS
539 sites.abbreviated_name,
547 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
548 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
549 site_persons.person_ids,
551 site_addresses.address_ids,
552 site_slices.slice_ids
554 LEFT JOIN site_persons USING (site_id)
555 LEFT JOIN site_nodes USING (site_id)
556 LEFT JOIN site_addresses USING (site_id)
557 LEFT JOIN site_slices USING (site_id);
559 CREATE VIEW view_addresses AS
561 addresses.address_id,
562 addresses.address_type,
568 addresses.postalcode,
572 LEFT JOIN site_address USING (address_id);
574 CREATE VIEW view_slices AS
579 slices.instantiation,
583 slices.creator_person_id,
585 CAST(date_part('epoch', slices.created) AS bigint) AS created,
586 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
587 slice_nodes.node_ids,
588 slice_persons.person_ids,
589 slice_attributes.attribute_ids
591 LEFT JOIN slice_nodes USING (slice_id)
592 LEFT JOIN slice_persons USING (slice_id)
593 LEFT JOIN slice_attributes USING (slice_id);
595 --------------------------------------------------------------------------------
596 -- Built-in maintenance account and default site
597 --------------------------------------------------------------------------------
600 (first_name, last_name, email, password, enabled)
602 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
604 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
605 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
606 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
607 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
610 (login_base, name, abbreviated_name, max_slices)
612 ('pl', 'PlanetLab Central', 'PLC', 100);