Add to git.
[monolith.git] / sql / ml_chat_create.sql
1 -- Create schema for monolith chat 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_chat_create.sql,v 1.1 2003/02/22 12:49:21 rich Exp $
7 --
8 -- Depends: monolith_core, monolith_users, monolith_auth, monolith_resources
9
10 begin work;
11
12 create table ml_chat_rooms
13 (
14         resid int4
15                 constraint ml_chat_rooms_resid_pk
16                 primary key
17                 references ml_resources (resid)
18                 on delete cascade,
19         allow_anon boolean      -- If true, allow anonymous postings
20                 default 'f'
21                 constraint ml_chat_rooms_allow_anon_nn
22                 not null
23 );
24
25 -- Postings are logged in this table. The chat software doesn't
26 -- actually pull postings out of this table when displaying the
27 -- page, because that would be too slow. This table is consulted
28 -- when the server starts up to populate the chat server's internal
29 -- data structures.
30
31 create table ml_chat_log
32 (
33         id serial,              -- Unique posting ID
34         resid int4              -- Which room does this belong to?
35                 constraint ml_chat_log_resid_nn
36                 not null
37                 references ml_chat_rooms (resid)
38                 on delete cascade,
39         body text               -- The posting
40                 constraint ml_chat_log_body_nn
41                 not null,
42         posted_date timestamp   -- When posted
43                 default current_timestamp
44                 constraint ml_chat_log_posted_date_nn
45                 not null,
46         author int4             -- Who posted (null == anonymous)
47                 references ml_users (userid)
48                 on delete set null,
49         original_ip inet        -- Originating IP address when posted
50                 constraint ml_chat_log_original_ip_nn
51                 not null
52 );
53
54 create table ml_chat_fill_buffers
55 (
56         size int2               -- Number of bytes to send
57                 constraint ml_chat_fill_buffers_size_nn
58                 not null
59                 constraint ml_chat_fill_buffers_pk
60                 primary key
61 );
62
63 create table ml_chat_userprefs
64 (
65         userid int4             -- The user ID.
66                 constraint ml_chat_userprefs_userid_nn
67                 not null
68                 references ml_users (userid)
69                 on delete cascade,
70         fill_buffer int2        -- Size of the fill buffer.
71                 default 4096
72                 constraint ml_chat_userprefs_fill_buffer_nn
73                 not null
74                 references ml_chat_fill_buffers (size)
75 );
76
77 -- Populate the tables.
78
79 insert into ml_chat_fill_buffers (size) values (0);
80 insert into ml_chat_fill_buffers (size) values (1024);
81 insert into ml_chat_fill_buffers (size) values (2048);
82 insert into ml_chat_fill_buffers (size) values (4096);
83 insert into ml_chat_fill_buffers (size) values (8192);
84 insert into ml_chat_fill_buffers (size) values (16384);
85
86 -- Grant access to the webservers
87
88 grant select on ml_chat_rooms to nobody;
89 grant select, insert on ml_chat_log to nobody;
90 grant select, update on ml_chat_log_id_seq to nobody;
91 grant select on ml_chat_fill_buffers to nobody;
92 grant select, insert, update, delete on ml_chat_userprefs to nobody;
93
94 commit work;