- added explicit 'WITH OIDS' when creating tables (tables are not created with oids...
[plcapi.git] / planetlab4.sql
1
2 -- PlanetLab Central database schema
3 -- Version 4, PostgreSQL
4 --
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>
9 --
10 -- Copyright (C) 2006 The Trustees of Princeton University
11 --
12 -- $Id: planetlab4.sql,v 1.4 2006/10/03 19:24:15 mlhuang Exp $
13 --
14
15 --------------------------------------------------------------------------------
16 -- Aggregates and store procedures
17 --------------------------------------------------------------------------------
18
19 -- Like MySQL GROUP_CONCAT(), this function aggregates values into a
20 -- PostgreSQL array.
21 CREATE AGGREGATE array_accum (
22     sfunc = array_append,
23     basetype = anyelement,
24     stype = anyarray,
25     initcond = '{}'
26 );
27
28 --------------------------------------------------------------------------------
29 -- Accounts
30 --------------------------------------------------------------------------------
31
32 -- Accounts
33 CREATE TABLE persons (
34     -- Mandatory
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
41
42     -- Password
43     password text NOT NULL, -- Password (md5crypted)
44     verification_key text, -- Reset password key
45     verification_expires timestamp without time zone,
46
47     -- Optional
48     title text, -- Honorific
49     phone text, -- Telephone number
50     url text, -- Home page
51     bio text, -- Biography
52
53     -- Timestamps
54     date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
55     last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
56 ) WITH OIDS;
57 CREATE INDEX persons_email_key ON persons (email) WHERE deleted IS false;
58
59 --------------------------------------------------------------------------------
60 -- Sites
61 --------------------------------------------------------------------------------
62
63 -- Sites
64 CREATE TABLE sites (
65     -- Mandatory
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
74
75     -- Optional
76     latitude real,
77     longitude real,
78     url text,
79
80     -- Timestamps
81     date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
82     last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
83 ) WITH OIDS;
84 CREATE INDEX sites_login_base_key ON sites (login_base) WHERE deleted IS false;
85
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)
92 );
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);
95
96 -- Ordered by primary site first
97 CREATE VIEW person_site_ordered AS
98 SELECT person_id, site_id
99 FROM person_site
100 ORDER BY is_primary DESC;
101
102 -- Sites that each person is a member of
103 CREATE VIEW person_sites AS
104 SELECT person_id,
105 array_to_string(array_accum(site_id), ',') AS site_ids
106 FROM person_site_ordered
107 GROUP BY person_id;
108
109 -- Accounts at each site
110 CREATE VIEW site_persons AS
111 SELECT site_id,
112 array_to_string(array_accum(person_id), ',') AS person_ids
113 FROM person_site
114 GROUP BY site_id;
115
116 --------------------------------------------------------------------------------
117 -- Mailing Addresses
118 --------------------------------------------------------------------------------
119
120 -- Mailing addresses
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
131 ) WITH OIDS;
132
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)
138 ) WITH OIDS;
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);
141
142 CREATE VIEW site_addresses AS
143 SELECT site_id,
144 array_to_string(array_accum(address_id), ',') AS address_ids
145 FROM site_address
146 GROUP BY site_id;
147
148 --------------------------------------------------------------------------------
149 -- Authentication Keys
150 --------------------------------------------------------------------------------
151
152 -- Valid key types
153 CREATE TABLE key_types (
154     key_type text PRIMARY KEY -- Key type
155 ) WITH OIDS;
156 INSERT INTO key_types (key_type) VALUES ('ssh');
157
158 -- Authentication keys
159 CREATE TABLE 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
164 ) WITH OIDS;
165
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)
172 ) WITH OIDS;
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);
175
176 CREATE VIEW person_keys AS
177 SELECT person_id,
178 array_to_string(array_accum(key_id), ',') AS key_ids
179 FROM person_key
180 GROUP BY person_id;
181
182 --------------------------------------------------------------------------------
183 -- Account roles
184 --------------------------------------------------------------------------------
185
186 -- Valid account roles
187 CREATE TABLE roles (
188     role_id integer PRIMARY KEY, -- Role identifier
189     name text UNIQUE NOT NULL -- Role symbolic name
190 ) WITH OIDS;
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');
197
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)
202 ) WITH OIDS;
203 CREATE INDEX person_role_person_id_key ON person_role (person_id);
204
205 -- Account roles
206 CREATE VIEW person_roles AS
207 SELECT person_id,
208 array_to_string(array_accum(role_id), ',') AS role_ids,
209 array_to_string(array_accum(roles.name), ',') AS roles
210 FROM person_role
211 LEFT JOIN roles USING (role_id)
212 GROUP BY person_id;
213
214 --------------------------------------------------------------------------------
215 -- Nodes
216 --------------------------------------------------------------------------------
217
218 -- Valid node boot states
219 CREATE TABLE boot_states (
220     boot_state text PRIMARY KEY
221 ) WITH OIDS;
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');
228
229 -- Nodes
230 CREATE TABLE nodes (
231     -- Mandatory
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
237
238     -- Optional
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
246
247     -- Timestamps
248     date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
249     last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
250 ) WITH OIDS;
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;
253
254 -- Nodes at each site
255 CREATE VIEW site_nodes AS
256 SELECT site_id,
257 array_to_string(array_accum(node_id), ',') AS node_ids
258 FROM nodes
259 GROUP BY site_id;
260
261 --------------------------------------------------------------------------------
262 -- Node groups
263 --------------------------------------------------------------------------------
264
265 -- Node groups
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
270 ) WITH OIDS;
271
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)
277 ) WITH OIDS;
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);
280
281 -- Nodes in each node gruop
282 CREATE VIEW nodegroup_nodes AS
283 SELECT nodegroup_id,
284 array_to_string(array_accum(node_id), ',') AS node_ids
285 FROM nodegroup_node
286 GROUP BY nodegroup_id;
287
288 -- Node groups that each node is a member of
289 CREATE VIEW node_nodegroups AS
290 SELECT node_id,
291 array_to_string(array_accum(nodegroup_id), ',') AS nodegroup_ids
292 FROM nodegroup_node
293 GROUP BY node_id;
294
295 --------------------------------------------------------------------------------
296 -- Node network interfaces
297 --------------------------------------------------------------------------------
298
299 -- Valid network addressing schemes
300 CREATE TABLE nodenetwork_types (
301     type text PRIMARY KEY -- Addressing scheme
302 ) WITH OIDS;
303 INSERT INTO nodenetwork_types (type) VALUES ('ipv4');
304 INSERT INTO nodenetwork_types (type) VALUES ('ipv6');
305
306 -- Valid network configuration methods
307 CREATE TABLE nodenetwork_methods (
308     method text PRIMARY KEY -- Configuration method
309 ) WITH OIDS;
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');
316
317 -- Node network interfaces
318 CREATE TABLE nodenetworks (
319     -- Mandatory
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
325
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
337 ) WITH OIDS;
338 CREATE INDEX nodenetworks_node_id_key ON nodenetworks (node_id);
339
340 -- Ordered by primary interface first
341 CREATE VIEW nodenetworks_ordered AS
342 SELECT node_id, nodenetwork_id
343 FROM nodenetworks
344 ORDER BY is_primary DESC;
345
346 -- Network interfaces on each node
347 CREATE VIEW node_nodenetworks AS
348 SELECT node_id,
349 array_to_string(array_accum(nodenetwork_id), ',') AS nodenetwork_ids
350 FROM nodenetworks_ordered
351 GROUP BY node_id;
352
353 --------------------------------------------------------------------------------
354 -- Slices
355 --------------------------------------------------------------------------------
356
357 CREATE TABLE slice_instantiations (
358     instantiation text PRIMARY KEY
359 ) WITH OIDS;
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
363
364 -- Slices
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
372
373     max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
374
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
378
379     is_deleted boolean NOT NULL DEFAULT false
380 ) WITH OIDS;
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;
383
384 -- Slivers
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
388 ) WITH OIDS;
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);
391
392 -- Synonym for slice_node
393 CREATE VIEW slivers AS
394 SELECT * FROM slice_node;
395
396 -- Nodes in each slice
397 CREATE VIEW slice_nodes AS
398 SELECT slice_id,
399 array_to_string(array_accum(node_id), ',') AS node_ids
400 FROM slice_node
401 GROUP BY slice_id;
402
403 -- Slices on each node
404 CREATE VIEW node_slices AS
405 SELECT node_id,
406 array_to_string(array_accum(slice_id), ',') AS slice_ids
407 FROM slice_node
408 GROUP BY node_id;
409
410 -- Slices at each site
411 CREATE VIEW site_slices AS
412 SELECT site_id,
413 array_to_string(array_accum(slice_id), ',') AS slice_ids
414 FROM slices
415 GROUP BY site_id;
416
417 -- Slice membership
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)
422 ) WITH OIDS;
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);
425
426 -- Members of the slice
427 CREATE VIEW slice_persons AS
428 SELECT slice_id,
429 array_to_string(array_accum(person_id), ',') AS person_ids
430 FROM slice_person
431 GROUP BY slice_id;
432
433 -- Slices of which each person is a member
434 CREATE VIEW person_slices AS
435 SELECT person_id,
436 array_to_string(array_accum(slice_id), ',') AS slice_ids
437 FROM slice_person
438 GROUP BY person_id;
439
440 --------------------------------------------------------------------------------
441 -- Attributes
442 --------------------------------------------------------------------------------
443
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
450 ) WITH OIDS;
451
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
458     value text
459 ) WITH OIDS;
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);
462
463 CREATE VIEW slice_attributes AS
464 SELECT slice_id,
465 array_to_string(array_accum(slice_attribute_id), ',') AS slice_attribute_ids
466 FROM slice_attribute
467 GROUP BY slice_id;
468
469 -- Node attributes
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
474     value text
475 ) WITH OIDS;
476 CREATE INDEX node_attribute_node_id_key ON node_attribute (node_id);
477
478 CREATE VIEW node_attributes AS
479 SELECT node_id,
480 array_to_string(array_accum(node_attribute_id), ',') AS node_attribute_ids
481 FROM node_attribute
482 GROUP BY node_id;
483
484 --------------------------------------------------------------------------------
485 -- Useful views
486 --------------------------------------------------------------------------------
487
488 CREATE VIEW view_persons AS
489 SELECT
490 persons.person_id,
491 persons.email,
492 persons.first_name,
493 persons.last_name,
494 persons.deleted,
495 persons.enabled,
496 persons.password,
497 persons.verification_key,
498 persons.verification_expires,
499 persons.title,
500 persons.phone,
501 persons.url,
502 persons.bio,
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,
507 person_keys.key_ids,
508 person_slices.slice_ids
509 FROM persons
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);
514
515 CREATE VIEW view_nodes AS
516 SELECT
517 nodes.node_id,
518 nodes.hostname,
519 nodes.site_id,
520 nodes.boot_state,
521 nodes.deleted,
522 nodes.model,
523 nodes.boot_nonce,
524 nodes.version,
525 nodes.ssh_rsa_key,
526 nodes.key,
527 nodes.session,
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
533 FROM nodes
534 LEFT JOIN node_nodenetworks USING (node_id)
535 LEFT JOIN node_nodegroups USING (node_id)
536 LEFT JOIN node_slices USING (node_id);
537
538 CREATE VIEW view_node_attributes AS
539 SELECT
540 node_attribute.node_attribute_id,
541 node_attribute.node_id,
542 attributes.attribute_id,
543 attributes.name,
544 attributes.description,
545 attributes.min_role_id,
546 node_attribute.value
547 FROM node_attribute
548 INNER JOIN attributes USING (attribute_id);
549
550 CREATE VIEW view_nodegroups AS
551 SELECT
552 nodegroups.nodegroup_id,
553 nodegroups.name,
554 nodegroups.description,
555 nodegroup_nodes.node_ids
556 FROM nodegroups
557 LEFT JOIN nodegroup_nodes USING (nodegroup_id);
558
559 CREATE VIEW view_sites AS
560 SELECT
561 sites.site_id,
562 sites.login_base,
563 sites.name,
564 sites.abbreviated_name,
565 sites.deleted,
566 sites.is_public,
567 sites.max_slices,
568 sites.max_slivers,
569 sites.latitude,
570 sites.longitude,
571 sites.url,
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,
575 site_nodes.node_ids,
576 site_addresses.address_ids,
577 site_slices.slice_ids
578 FROM sites
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);
583
584 CREATE VIEW view_addresses AS
585 SELECT
586 addresses.address_id,
587 addresses.address_type,
588 addresses.line1,
589 addresses.line2,
590 addresses.line3,
591 addresses.city,
592 addresses.state,
593 addresses.postalcode,
594 addresses.country,
595 site_address.site_id
596 FROM addresses
597 LEFT JOIN site_address USING (address_id);
598
599 CREATE VIEW view_slices AS
600 SELECT
601 slices.slice_id,
602 slices.site_id,
603 slices.name,
604 slices.instantiation,
605 slices.url,
606 slices.description,
607 slices.max_nodes,
608 slices.creator_person_id,
609 slices.is_deleted,
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
615 FROM slices
616 LEFT JOIN slice_nodes USING (slice_id)
617 LEFT JOIN slice_persons USING (slice_id)
618 LEFT JOIN slice_attributes USING (slice_id);
619
620 CREATE VIEW view_slice_attributes AS
621 SELECT
622 slice_attribute.slice_attribute_id,
623 slice_attribute.slice_id,
624 slice_attribute.node_id,
625 attributes.attribute_id,
626 attributes.name,
627 attributes.description,
628 attributes.min_role_id,
629 slice_attribute.value
630 FROM slice_attribute
631 INNER JOIN attributes USING (attribute_id);
632
633 --------------------------------------------------------------------------------
634 -- Built-in maintenance account and default site
635 --------------------------------------------------------------------------------
636
637 INSERT INTO persons
638 (first_name, last_name, email, password, enabled)
639 VALUES
640 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
641
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);
646
647 INSERT INTO sites
648 (login_base, name, abbreviated_name, max_slices)
649 VALUES
650 ('pl', 'PlanetLab Central', 'PLC', 100);