annotate schema.sql @ 2:791e87929f83 default tip

Added tag RELENG_1_0 for changeset d95e74cd12f4
author darius@midget.dons.net.au
date Tue, 23 Oct 2007 10:07:21 +0930
parents d95e74cd12f4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
1 -- Create schema for the SCS member and event database.
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
2
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
3 -- Drop tables and sequences used
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
4 DROP FUNCTION mailto(int4);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
5 DROP TABLE mem_ev_lnk;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
6 DROP TABLE events;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
7 DROP SEQUENCE event_id;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
8 DROP TABLE members;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
9 DROP SEQUENCE member_id;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
10
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
11 -- Sequence for Member ID's
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
12 CREATE SEQUENCE member_id INCREMENT 1 START 1;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
13
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
14 -- Member table.
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
15 CREATE TABLE members (
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
16 memberid int4 NOT NULL,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
17 firstname char(25) NOT NULL,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
18 lastname char(25) NOT NULL,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
19 nickname char(20),
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
20 pin char(10),
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
21 age int2,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
22 phone1 char(20),
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
23 ph1_pub bool,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
24 phone2 char(20),
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
25 ph2_pub bool,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
26 email char(70) NOT NULL,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
27 email_pub bool,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
28 address1 char(30),
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
29 address2 char(30),
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
30 address3 char(30),
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
31 addy_pub bool,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
32 comments text,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
33 joined date,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
34 lastmembfee money,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
35 lastpaiddate date,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
36
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
37 PRIMARY KEY (memberid),
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
38
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
39 CONSTRAINT memcon CHECK (firstname <> ''), CHECK (lastname <> ''), CHECK (nickname <> ''),
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
40 CHECK (memberid > 0)
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
41 );
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
42
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
43 -- Sequence for Event ID's
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
44 CREATE SEQUENCE event_id INCREMENT 1 START 1;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
45
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
46 -- Event table.
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
47 CREATE TABLE events (
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
48 eventid int4 NOT NULL,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
49 name text NOT NULL,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
50 description text NOT NULL,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
51 when datetime NOT NULL,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
52 duration timespan,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
53 cost text NOT NULL,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
54 contact text NOT NULL,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
55
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
56 PRIMARY KEY (eventid),
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
57
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
58 CONSTRAINT evcon CHECK (eventid > 0), CHECK (name <> ''), CHECK (description <> ''),
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
59 CHECK (cost <> ''), CHECK (contact <> '')
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
60 );
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
61
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
62 -- Table to link the Event table and the Member ID table
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
63 CREATE TABLE mem_ev_lnk (
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
64 memberid int4,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
65 eventid int4,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
66 contact bool,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
67
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
68 FOREIGN KEY (memberid) REFERENCES members,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
69 FOREIGN KEY (eventid) REFERENCES events,
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
70
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
71 CONSTRAINT lnkcon CHECK (memberid > 0), CHECK (eventid > 0)
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
72 );
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
73
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
74 -- Function which returns a list of email addresses to mail about a
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
75 -- given eventid
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
76 CREATE FUNCTION mailto(int4) RETURNS SETOF bpchar AS
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
77 'SELECT email FROM members WHERE memberid IN
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
78 (SELECT memberid FROM mem_ev_lnk WHERE eventid = $1 AND contact = \'yes\')'
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
79 LANGUAGE 'sql';
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
80
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
81 GRANT SELECT, INSERT, UPDATE ON members, events, mem_ev_lnk TO www;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
82 GRANT SELECT, INSERT, UPDATE ON members, events, mem_ev_lnk TO darius;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
83