Add to git.
[monolith.git] / sql / ml_calendar_create.sql
1 -- Create schema for monolith calendar widget.
2 -- Copyright (C) 2002 Richard W.M. Jones <rich@annexia.org>
3 -- This code is NOT REDISTRIBUTABLE. To use this widget you must purchase
4 -- a license at http://www.annexia.org/
5 --
6 -- $Id: ml_calendar_create.sql,v 1.1 2003/02/22 12:49:20 rich Exp $
7 --
8 -- Depends: monolith_core, monolith_users, monolith_auth, monolith_resources
9
10 begin work;
11
12 create table ml_calendar
13 (
14         resid int4
15                 constraint ml_calendar_resid_pk
16                 primary key
17                 references ml_resources (resid)
18                 on delete cascade
19 );
20
21 create table ml_calendar_events
22 (
23         id serial,              -- Unique event number
24         resid int4              -- Which calendar does this belong to?
25                 constraint ml_calendar_events_resid_nn
26                 not null
27                 references ml_calendar (resid)
28                 on delete cascade,
29
30         -- Start and length of the event. As a special case, events
31         -- which have length == 24 hours are day events, and are shown
32         -- as notes next to each day instead of on the calendar.
33         start_time timestamp    -- Start of the event
34                 constraint ml_calendar_events_start_time_nn
35                 not null,
36         length interval         -- Length of the event
37                 constraint ml_calendar_events_length_nn
38                 not null,
39
40         -- One-off events set these to null. Recurring events set period
41         -- to period of recurrence, usually 1 day, 1 week, 1 month or 1 year.
42         -- If the last_time is set, then a recurring event ceases _after_
43         -- this time.
44         period interval,        -- Recurrence period
45         last_time timestamp,    -- Last recurrence of the event
46
47         alert interval,         -- Send alert this interval before event
48         last_alert timestamp,   -- Last date an alert was sent for this event
49         alert_userid int4       -- Who to send the alert to
50                 references ml_users (userid)
51                 on delete set null,
52
53         subject text            -- Short text description
54                 constraint ml_calendar_events_title_nn
55                 not null,
56         body text,              -- Optional longer note
57
58         posted_date timestamp   -- When entered into calendar
59                 default current_timestamp
60                 constraint ml_calendar_events_posted_date_nn
61                 not null,
62         last_modified_date timestamp -- When last modified
63                 default current_timestamp
64                 constraint ml_calendar_last_modified_date_nn
65                 not null,
66         author int4             -- Who last modified
67                 constraint ml_calendar_events_author_nn
68                 not null
69                 references ml_users (userid)
70                 on delete cascade,
71         original_ip inet        -- Originating IP address when posted
72                 constraint ml_calendar_events_original_ip_nn
73                 not null
74 );
75
76 -- Grant access to the webservers
77
78 grant select on ml_calendar to nobody;
79 grant select, insert, update, delete on ml_calendar_events to nobody;
80 grant select, update on ml_calendar_events_id_seq to nobody;
81
82 commit work;