ship database schema in a separate file
[sfa.git] / sfa / storage / sfa.sql
1 --
2 -- SFA database schema
3 --
4
5 SET client_encoding = 'UNICODE';
6
7 --------------------------------------------------------------------------------
8 -- Version
9 --------------------------------------------------------------------------------
10
11 -- Database version
12 CREATE TABLE sfa_db_version (
13     version integer NOT NULL,
14     subversion integer NOT NULL DEFAULT 0
15 ) WITH OIDS;
16
17 -- the migration scripts do not use the major 'version' number
18 -- so 5.0 sets subversion at 100
19 -- in case your database misses the site and persons tags feature, 
20 -- you might wish to first upgrade to 4.3-rc16 before moving to some 5.0
21 -- or run the up script here
22 -- http://svn.planet-lab.org/svn/PLCAPI/branches/4.3/migrations/
23
24 INSERT INTO sfa_db_version (version, subversion) VALUES (1, 1);
25
26 --------------------------------------------------------------------------------
27 -- Aggregates and store procedures
28 --------------------------------------------------------------------------------
29
30 -- Like MySQL GROUP_CONCAT(), this function aggregates values into a
31 -- PostgreSQL array.
32 CREATE AGGREGATE array_accum (
33     sfunc = array_append,
34     basetype = anyelement,
35     stype = anyarray,
36     initcond = '{}'
37 );
38
39 -- main table 
40 CREATE TABLE sfa ( 
41     record_id serial PRIMARY KEY , 
42     hrn text NOT NULL, 
43     authority text NOT NULL, 
44     peer_authority text, 
45     gid text, 
46     type text NOT NULL, 
47     pointer integer, 
48     date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, 
49     last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
50 );
51 CREATE INDEX sfa_hrn_ids on sfa (hrn);
52 CREATE INDEX sfa_type_ids on sfa (type);
53 CREATE INDEX sfa_authority_ids on sfa (authority);
54 CREATE INDEX sfa_peer_authority_ids on sfa (peer_authority);
55 CREATE INDEX sfa_pointer_ids on sfa (pointer);