Add to git.
[monolith.git] / sql / ml_bulletins_create.sql
1 -- Create schema for ml_bulletins widget.
2 -- - by Richard W.M. Jones <rich@annexia.org>
3 --
4 -- This library is free software; you can redistribute it and/or
5 -- modify it under the terms of the GNU Library General Public
6 -- License as published by the Free Software Foundation; either
7 -- version 2 of the License, or (at your option) any later version.
8 --
9 -- This library is distributed in the hope that it will be useful,
10 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 -- Library General Public License for more details.
13 --
14 -- You should have received a copy of the GNU Library General Public
15 -- License along with this library; if not, write to the Free
16 -- Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 --
18 -- $Id: ml_bulletins_create.sql,v 1.7 2002/11/15 20:46:03 rich Exp $
19 --
20 -- Depends: monolith_core, monolith_users, monolith_auth, monolith_resources
21
22 begin work;
23
24 create table ml_bulletins_sections
25 (
26         resid int4
27                 constraint ml_bulletins_sections_resid_pk
28                 primary key
29                 references ml_resources (resid)
30                 on delete cascade
31 );
32
33 create table ml_bulletins_posters
34 (
35         sectionid int4          -- The section
36                 references ml_bulletins_sections (resid)
37                 on delete cascade,
38         userid int4             -- The user who can post in this section
39                 references ml_users (userid)
40                 on delete cascade
41 );
42
43 create unique index ml_bulletins_posters_ui
44         on ml_bulletins_posters (sectionid, userid);
45
46 create table ml_bulletins
47 (
48         id serial,
49         sectionid int4          -- Which section is this in?
50                 constraint ml_bulletins_sectionid_nn
51                 not null
52                 references ml_bulletins_sections (resid)
53                 on delete cascade,
54         authorid int4
55                 constraint ml_bulletins_authorid_nn
56                 not null
57                 references ml_users (userid)
58                 on delete cascade,
59         item text               -- The text body of the item
60                 constraint ml_bulletins_item_nn
61                 not null,
62         item_type char(1)       -- Type: plain, smart, HTML
63                 constraint ml_bulletins_item_type_nn
64                 not null
65                 constraint ml_bulletins_item_type_ck
66                 check (item_type in ('p', 's', 'h')),
67         posted_date timestamp   -- Date that this item was posted
68                 default current_timestamp
69                 constraint ml_bulletins_timestamp_nn
70                 not null,
71         link text,              -- Optional link
72         link_text text          -- Optional text on the link
73 );
74
75 create index ml_bulletins_sectionid_i on ml_bulletins (sectionid);
76
77 -- Allow the web server to access this table.
78 grant select, insert, update, delete on ml_bulletins_sections to nobody;
79 grant select, insert, delete on ml_bulletins_posters to nobody;
80 grant select, insert, update, delete on ml_bulletins to nobody;
81 grant select, update on ml_bulletins_id_seq to nobody;
82
83 commit work;