- add address_types back
[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.5 2006/10/06 15:41:50 tmack 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 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
124 );
125 INSERT INTO address_types (name) VALUES ('Personal');
126 INSERT INTO address_types (name) VALUES ('Shipping');
127 -- XXX Used to be Site
128 INSERT INTO address_types (name) VALUES ('Billing');
129
130 -- Mailing addresses
131 CREATE TABLE addresses (
132     address_id serial PRIMARY KEY, -- Address identifier
133     site_id integer REFERENCES sites NOT NULL, -- Site 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
141 ) WITH OIDS;
142
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 ) WITH OIDS;
148
149 CREATE VIEW address_address_types AS
150 SELECT address_id,
151 array_to_string(array_accum(address_type_id), ',') AS address_type_ids,
152 array_to_string(array_accum(address_types.name), ',') AS address_types
153 FROM address_address_type
154 LEFT JOIN address_types USING (address_type_id)
155 GROUP BY address_id;
156
157 CREATE VIEW site_addresses AS
158 SELECT site_id,
159 array_to_string(array_accum(address_id), ',') AS address_ids
160 FROM addresses
161 GROUP BY site_id;
162
163 --------------------------------------------------------------------------------
164 -- Authentication Keys
165 --------------------------------------------------------------------------------
166
167 -- Valid key types
168 CREATE TABLE key_types (
169     key_type text PRIMARY KEY -- Key type
170 ) WITH OIDS;
171 INSERT INTO key_types (key_type) VALUES ('ssh');
172
173 -- Authentication keys
174 CREATE TABLE keys (
175     key_id serial PRIMARY KEY, -- Key identifier
176     key_type text REFERENCES key_types NOT NULL, -- Key type
177     key text NOT NULL, -- Key material
178     is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
179 ) WITH OIDS;
180
181 -- Account authentication key(s)
182 CREATE TABLE person_key (
183     person_id integer REFERENCES persons NOT NULL, -- Account identifier
184     key_id integer REFERENCES keys NOT NULL, -- Key identifier
185     is_primary boolean NOT NULL DEFAULT false, -- Is the primary key for this account
186     PRIMARY KEY (person_id, key_id)
187 ) WITH OIDS;
188 CREATE INDEX person_key_person_id_key ON person_key (person_id);
189 CREATE INDEX person_key_key_id_key ON person_key (key_id);
190
191 CREATE VIEW person_keys AS
192 SELECT person_id,
193 array_to_string(array_accum(key_id), ',') AS key_ids
194 FROM person_key
195 GROUP BY person_id;
196
197 --------------------------------------------------------------------------------
198 -- Account roles
199 --------------------------------------------------------------------------------
200
201 -- Valid account roles
202 CREATE TABLE roles (
203     role_id integer PRIMARY KEY, -- Role identifier
204     name text UNIQUE NOT NULL -- Role symbolic name
205 ) WITH OIDS;
206 INSERT INTO roles (role_id, name) VALUES (10, 'admin');
207 INSERT INTO roles (role_id, name) VALUES (20, 'pi');
208 INSERT INTO roles (role_id, name) VALUES (30, 'user');
209 INSERT INTO roles (role_id, name) VALUES (40, 'tech');
210 INSERT INTO roles (role_id, name) VALUES (1000, 'node');
211 INSERT INTO roles (role_id, name) VALUES (2000, 'anonymous');
212
213 CREATE TABLE person_role (
214     person_id integer REFERENCES persons NOT NULL, -- Account identifier
215     role_id integer REFERENCES roles NOT NULL, -- Role identifier
216     PRIMARY KEY (person_id, role_id)
217 ) WITH OIDS;
218 CREATE INDEX person_role_person_id_key ON person_role (person_id);
219
220 -- Account roles
221 CREATE VIEW person_roles AS
222 SELECT person_id,
223 array_to_string(array_accum(role_id), ',') AS role_ids,
224 array_to_string(array_accum(roles.name), ',') AS roles
225 FROM person_role
226 LEFT JOIN roles USING (role_id)
227 GROUP BY person_id;
228
229 --------------------------------------------------------------------------------
230 -- Nodes
231 --------------------------------------------------------------------------------
232
233 -- Valid node boot states
234 CREATE TABLE boot_states (
235     boot_state text PRIMARY KEY
236 ) WITH OIDS;
237 INSERT INTO boot_states (boot_state) VALUES ('boot');
238 INSERT INTO boot_states (boot_state) VALUES ('dbg');
239 INSERT INTO boot_states (boot_state) VALUES ('inst');
240 INSERT INTO boot_states (boot_state) VALUES ('rins');
241 INSERT INTO boot_states (boot_state) VALUES ('rcnf');
242 INSERT INTO boot_states (boot_state) VALUES ('new');
243
244 -- Nodes
245 CREATE TABLE nodes (
246     -- Mandatory
247     node_id serial PRIMARY KEY, -- Node identifier
248     hostname text NOT NULL, -- Node hostname
249     site_id integer REFERENCES sites NOT NULL, -- At which site
250     boot_state text REFERENCES boot_states NOT NULL, -- Node boot state
251     deleted boolean NOT NULL DEFAULT false, -- Is deleted
252
253     -- Optional
254     model text, -- Hardware make and model
255     boot_nonce text, -- Random nonce updated by Boot Manager
256     version text, -- Boot CD version string updated by Boot Manager
257     -- XXX Should be key_id integer REFERENCES keys
258     ssh_rsa_key text, -- SSH host key updated by Boot Manager
259     key text, -- Node key generated by API when configuration file is downloaded
260     session text, -- Session key generated by PLC when Boot Manager authenticates
261
262     -- Timestamps
263     date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
264     last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
265 ) WITH OIDS;
266 CREATE INDEX nodes_hostname_key ON nodes (hostname) WHERE deleted IS false;
267 CREATE INDEX nodes_site_id_key ON nodes (site_id) WHERE deleted IS false;
268
269 -- Nodes at each site
270 CREATE VIEW site_nodes AS
271 SELECT site_id,
272 array_to_string(array_accum(node_id), ',') AS node_ids
273 FROM nodes
274 GROUP BY site_id;
275
276 --------------------------------------------------------------------------------
277 -- Node groups
278 --------------------------------------------------------------------------------
279
280 -- Node groups
281 CREATE TABLE nodegroups (
282     nodegroup_id serial PRIMARY KEY, -- Group identifier
283     name text UNIQUE NOT NULL, -- Group name
284     description text -- Group description
285 ) WITH OIDS;
286
287 -- Node group membership
288 CREATE TABLE nodegroup_node (
289     nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Group identifier
290     node_id integer REFERENCES nodes NOT NULL, -- Node identifier
291     PRIMARY KEY (nodegroup_id, node_id)
292 ) WITH OIDS;
293 CREATE INDEX nodegroup_node_nodegroup_id_key ON nodegroup_node (nodegroup_id);
294 CREATE INDEX nodegroup_node_node_id_key ON nodegroup_node (node_id);
295
296 -- Nodes in each node gruop
297 CREATE VIEW nodegroup_nodes AS
298 SELECT nodegroup_id,
299 array_to_string(array_accum(node_id), ',') AS node_ids
300 FROM nodegroup_node
301 GROUP BY nodegroup_id;
302
303 -- Node groups that each node is a member of
304 CREATE VIEW node_nodegroups AS
305 SELECT node_id,
306 array_to_string(array_accum(nodegroup_id), ',') AS nodegroup_ids
307 FROM nodegroup_node
308 GROUP BY node_id;
309
310 --------------------------------------------------------------------------------
311 -- Node network interfaces
312 --------------------------------------------------------------------------------
313
314 -- Valid network addressing schemes
315 CREATE TABLE nodenetwork_types (
316     type text PRIMARY KEY -- Addressing scheme
317 ) WITH OIDS;
318 INSERT INTO nodenetwork_types (type) VALUES ('ipv4');
319 INSERT INTO nodenetwork_types (type) VALUES ('ipv6');
320
321 -- Valid network configuration methods
322 CREATE TABLE nodenetwork_methods (
323     method text PRIMARY KEY -- Configuration method
324 ) WITH OIDS;
325 INSERT INTO nodenetwork_methods (method) VALUES ('static');
326 INSERT INTO nodenetwork_methods (method) VALUES ('dhcp');
327 INSERT INTO nodenetwork_methods (method) VALUES ('proxy');
328 INSERT INTO nodenetwork_methods (method) VALUES ('tap');
329 INSERT INTO nodenetwork_methods (method) VALUES ('ipmi');
330 INSERT INTO nodenetwork_methods (method) VALUES ('unknown');
331
332 -- Node network interfaces
333 CREATE TABLE nodenetworks (
334     -- Mandatory
335     nodenetwork_id serial PRIMARY KEY, -- Network interface identifier
336     node_id integer REFERENCES nodes NOT NULL, -- Which node
337     is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
338     type text REFERENCES nodenetwork_types NOT NULL, -- Addressing scheme
339     method text REFERENCES nodenetwork_methods NOT NULL, -- Configuration method
340
341     -- Optional, depending on type and method
342     ip text, -- IP address
343     mac text, -- MAC address
344     gateway text, -- Default gateway address
345     network text, -- Network address
346     broadcast text, -- Network broadcast address
347     netmask text, -- Network mask
348     dns1 text, -- Primary DNS server
349     dns2 text, -- Secondary DNS server
350     bwlimit integer, -- Bandwidth limit in bps
351     hostname text -- Hostname of this interface
352 ) WITH OIDS;
353 CREATE INDEX nodenetworks_node_id_key ON nodenetworks (node_id);
354
355 -- Ordered by primary interface first
356 CREATE VIEW nodenetworks_ordered AS
357 SELECT node_id, nodenetwork_id
358 FROM nodenetworks
359 ORDER BY is_primary DESC;
360
361 -- Network interfaces on each node
362 CREATE VIEW node_nodenetworks AS
363 SELECT node_id,
364 array_to_string(array_accum(nodenetwork_id), ',') AS nodenetwork_ids
365 FROM nodenetworks_ordered
366 GROUP BY node_id;
367
368 --------------------------------------------------------------------------------
369 -- Slices
370 --------------------------------------------------------------------------------
371
372 CREATE TABLE slice_instantiations (
373     instantiation text PRIMARY KEY
374 ) WITH OIDS;
375 INSERT INTO slice_instantiations (instantiation) VALUES ('not-instantiated'); -- Placeholder slice
376 INSERT INTO slice_instantiations (instantiation) VALUES ('plc-instantiated'); -- Instantiated by Node Manager
377 INSERT INTO slice_instantiations (instantiation) VALUES ('delegated'); -- Manually instantiated
378
379 -- Slices
380 CREATE TABLE slices (
381     slice_id serial PRIMARY KEY, -- Slice identifier
382     site_id integer REFERENCES sites NOT NULL, -- Site identifier
383     name text NOT NULL, -- Slice name
384     instantiation text REFERENCES slice_instantiations NOT NULL DEFAULT 'plc-instantiated', -- Slice state, e.g. plc-instantiated
385     url text, -- Project URL
386     description text, -- Project description
387
388     max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
389
390     creator_person_id integer REFERENCES persons NOT NULL, -- Creator
391     created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Creation date
392     expires timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP + '2 weeks', -- Expiration date
393
394     is_deleted boolean NOT NULL DEFAULT false
395 ) WITH OIDS;
396 CREATE INDEX slices_site_id_key ON slices (site_id) WHERE is_deleted IS false;
397 CREATE INDEX slices_name_key ON slices (name) WHERE is_deleted IS false;
398
399 -- Slivers
400 CREATE TABLE slice_node (
401     slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
402     node_id integer REFERENCES nodes NOT NULL -- Node identifier
403 ) WITH OIDS;
404 CREATE INDEX slice_node_slice_id_key ON slice_node (slice_id);
405 CREATE INDEX slice_node_node_id_key ON slice_node (node_id);
406
407 -- Synonym for slice_node
408 CREATE VIEW slivers AS
409 SELECT * FROM slice_node;
410
411 -- Nodes in each slice
412 CREATE VIEW slice_nodes AS
413 SELECT slice_id,
414 array_to_string(array_accum(node_id), ',') AS node_ids
415 FROM slice_node
416 GROUP BY slice_id;
417
418 -- Slices on each node
419 CREATE VIEW node_slices AS
420 SELECT node_id,
421 array_to_string(array_accum(slice_id), ',') AS slice_ids
422 FROM slice_node
423 GROUP BY node_id;
424
425 -- Slices at each site
426 CREATE VIEW site_slices AS
427 SELECT site_id,
428 array_to_string(array_accum(slice_id), ',') AS slice_ids
429 FROM slices
430 GROUP BY site_id;
431
432 -- Slice membership
433 CREATE TABLE slice_person (
434     slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
435     person_id integer REFERENCES persons NOT NULL, -- Account identifier
436     PRIMARY KEY (slice_id, person_id)
437 ) WITH OIDS;
438 CREATE INDEX slice_person_slice_id_key ON slice_person (slice_id);
439 CREATE INDEX slice_person_person_id_key ON slice_person (person_id);
440
441 -- Members of the slice
442 CREATE VIEW slice_persons AS
443 SELECT slice_id,
444 array_to_string(array_accum(person_id), ',') AS person_ids
445 FROM slice_person
446 GROUP BY slice_id;
447
448 -- Slices of which each person is a member
449 CREATE VIEW person_slices AS
450 SELECT person_id,
451 array_to_string(array_accum(slice_id), ',') AS slice_ids
452 FROM slice_person
453 GROUP BY person_id;
454
455 --------------------------------------------------------------------------------
456 -- Attributes
457 --------------------------------------------------------------------------------
458
459 -- Generic attribute types
460 CREATE TABLE attributes (
461     attribute_id serial PRIMARY KEY, -- Attribute type identifier
462     name text UNIQUE NOT NULL, -- Attribute name
463     description text, -- Attribute description
464     min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can set or change this attribute
465 ) WITH OIDS;
466
467 -- Slice/sliver attributes
468 CREATE TABLE slice_attribute (
469     slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier
470     slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
471     node_id integer REFERENCES nodes, -- Sliver attribute if set
472     attribute_id integer REFERENCES attributes NOT NULL, -- Attribute identifier
473     value text
474 ) WITH OIDS;
475 CREATE INDEX slice_attribute_slice_id_key ON slice_attribute (slice_id);
476 CREATE INDEX slice_attribute_node_id_key ON slice_attribute (node_id);
477
478 CREATE VIEW slice_attributes AS
479 SELECT slice_id,
480 array_to_string(array_accum(slice_attribute_id), ',') AS slice_attribute_ids
481 FROM slice_attribute
482 GROUP BY slice_id;
483
484 -- Node attributes
485 CREATE TABLE node_attribute (
486     node_attribute_id serial PRIMARY KEY, -- Node attribute identifier
487     node_id integer REFERENCES nodes NOT NULL, -- Node identifier
488     attribute_id integer REFERENCES attributes NOT NULL, -- Attribute identifier
489     value text
490 ) WITH OIDS;
491 CREATE INDEX node_attribute_node_id_key ON node_attribute (node_id);
492
493 CREATE VIEW node_attributes AS
494 SELECT node_id,
495 array_to_string(array_accum(node_attribute_id), ',') AS node_attribute_ids
496 FROM node_attribute
497 GROUP BY node_id;
498
499 --------------------------------------------------------------------------------
500 -- Useful views
501 --------------------------------------------------------------------------------
502
503 CREATE VIEW view_persons AS
504 SELECT
505 persons.person_id,
506 persons.email,
507 persons.first_name,
508 persons.last_name,
509 persons.deleted,
510 persons.enabled,
511 persons.password,
512 persons.verification_key,
513 persons.verification_expires,
514 persons.title,
515 persons.phone,
516 persons.url,
517 persons.bio,
518 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
519 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
520 person_roles.role_ids, person_roles.roles,
521 person_sites.site_ids,
522 person_keys.key_ids,
523 person_slices.slice_ids
524 FROM persons
525 LEFT JOIN person_roles USING (person_id)
526 LEFT JOIN person_sites USING (person_id)
527 LEFT JOIN person_keys USING (person_id)
528 LEFT JOIN person_slices USING (person_id);
529
530 CREATE VIEW view_nodes AS
531 SELECT
532 nodes.node_id,
533 nodes.hostname,
534 nodes.site_id,
535 nodes.boot_state,
536 nodes.deleted,
537 nodes.model,
538 nodes.boot_nonce,
539 nodes.version,
540 nodes.ssh_rsa_key,
541 nodes.key,
542 nodes.session,
543 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
544 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
545 node_nodenetworks.nodenetwork_ids,
546 node_nodegroups.nodegroup_ids,
547 node_slices.slice_ids
548 FROM nodes
549 LEFT JOIN node_nodenetworks USING (node_id)
550 LEFT JOIN node_nodegroups USING (node_id)
551 LEFT JOIN node_slices USING (node_id);
552
553 CREATE VIEW view_node_attributes AS
554 SELECT
555 node_attribute.node_attribute_id,
556 node_attribute.node_id,
557 attributes.attribute_id,
558 attributes.name,
559 attributes.description,
560 attributes.min_role_id,
561 node_attribute.value
562 FROM node_attribute
563 INNER JOIN attributes USING (attribute_id);
564
565 CREATE VIEW view_nodegroups AS
566 SELECT
567 nodegroups.nodegroup_id,
568 nodegroups.name,
569 nodegroups.description,
570 nodegroup_nodes.node_ids
571 FROM nodegroups
572 LEFT JOIN nodegroup_nodes USING (nodegroup_id);
573
574 CREATE VIEW view_sites AS
575 SELECT
576 sites.site_id,
577 sites.login_base,
578 sites.name,
579 sites.abbreviated_name,
580 sites.deleted,
581 sites.is_public,
582 sites.max_slices,
583 sites.max_slivers,
584 sites.latitude,
585 sites.longitude,
586 sites.url,
587 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
588 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
589 site_persons.person_ids,
590 site_nodes.node_ids,
591 site_addresses.address_ids,
592 site_slices.slice_ids
593 FROM sites
594 LEFT JOIN site_persons USING (site_id)
595 LEFT JOIN site_nodes USING (site_id)
596 LEFT JOIN site_addresses USING (site_id)
597 LEFT JOIN site_slices USING (site_id);
598
599 CREATE VIEW view_addresses AS
600 SELECT
601 addresses.address_id,
602 addresses.site_id,
603 addresses.line1,
604 addresses.line2,
605 addresses.line3,
606 addresses.city,
607 addresses.state,
608 addresses.postalcode,
609 addresses.country,
610 address_address_types.address_type_ids,
611 address_address_types.address_types
612 FROM addresses
613 LEFT JOIN address_address_types USING (address_id);
614
615 CREATE VIEW view_slices AS
616 SELECT
617 slices.slice_id,
618 slices.site_id,
619 slices.name,
620 slices.instantiation,
621 slices.url,
622 slices.description,
623 slices.max_nodes,
624 slices.creator_person_id,
625 slices.is_deleted,
626 CAST(date_part('epoch', slices.created) AS bigint) AS created,
627 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
628 slice_nodes.node_ids,
629 slice_persons.person_ids,
630 slice_attributes.slice_attribute_ids
631 FROM slices
632 LEFT JOIN slice_nodes USING (slice_id)
633 LEFT JOIN slice_persons USING (slice_id)
634 LEFT JOIN slice_attributes USING (slice_id);
635
636 CREATE VIEW view_slice_attributes AS
637 SELECT
638 slice_attribute.slice_attribute_id,
639 slice_attribute.slice_id,
640 slice_attribute.node_id,
641 attributes.attribute_id,
642 attributes.name,
643 attributes.description,
644 attributes.min_role_id,
645 slice_attribute.value
646 FROM slice_attribute
647 INNER JOIN attributes USING (attribute_id);
648
649 --------------------------------------------------------------------------------
650 -- Built-in maintenance account and default site
651 --------------------------------------------------------------------------------
652
653 INSERT INTO persons
654 (first_name, last_name, email, password, enabled)
655 VALUES
656 ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
657
658 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
659 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
660 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
661 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
662
663 INSERT INTO sites
664 (login_base, name, abbreviated_name, max_slices)
665 VALUES
666 ('pl', 'PlanetLab Central', 'PLC', 100);