2 # Simple script to generate input to psql to generate tables for a list
3 # All tables are created, even though it is not advisable to put e.g. the
4 # moderator table in the SQL database nor is it very useful to put the
5 # blacklist/deny table there. The subscriber lists for the main and digest
6 # lists should be there, and it's reasonable to put the "extra" list there
18 # not everyone has getopt :-(
19 while [ "`${ECHO} "$1" | ${CUT} -c1`" = "-" ]; do
21 -c) CREATE='y'; shift;;
22 -C) CREATE='n'; shift;;
25 -cd|-dc) CREATE='y'; DROP='y'; shift;;
26 -cD|-Dc) CREATE='y'; DROP='n'; shift;;
27 -Cd|-dC) CREATE='n'; DROP='y'; shift;;
28 -CD|-DC) CREATE='n'; DROP='n'; shift;;
30 *) echo "usage: emzlm-mktab [-cCdD] table_toot"; exit 100;;
34 [ ! -z "$1" ] && TROOT="$1";
36 if [ "$DROP" = "y" ]; then
39 /* drop old tables. */
41 /* ezmlm-mktab [-d] troot | psql -h host -u userid -d database */
44 DROP TABLE ${TROOT}_slog;
45 DROP TABLE ${TROOT}_digest;
46 DROP TABLE ${TROOT}_digest_slog;
47 DROP TABLE ${TROOT}_mod;
48 DROP TABLE ${TROOT}_mod_slog;
49 DROP TABLE ${TROOT}_allow;
50 DROP TABLE ${TROOT}_allow_slog;
51 DROP TABLE ${TROOT}_deny;
52 DROP TABLE ${TROOT}_deny_slog;
53 DROP TABLE ${TROOT}_name;
54 DROP TABLE ${TROOT}_cookie;
55 DROP TABLE ${TROOT}_mlog;
56 DROP TABLE ${TROOT}_digest_name;
57 DROP TABLE ${TROOT}_digest_cookie;
58 DROP TABLE ${TROOT}_digest_mlog;
59 DROP SEQUENCE ${TROOT}_name_listno_seq;
60 DROP SEQUENCE ${TROOT}_digest_name_listno_seq;
66 if [ $CREATE = 'y' ]; then
69 /* Main address table */
70 create TABLE ${TROOT} (
72 address VARCHAR(255) PRIMARY KEY );
74 /* Subscription log table. No addr idx to make insertion fast, since that is */
75 /* almost the only thing we do with this table */
76 create TABLE ${TROOT}_slog (
77 tai TIMESTAMP DEFAULT now(),
78 address VARCHAR(255) NOT NULL,
79 fromline VARCHAR(255) NOT NULL,
84 /* digest list table */
85 create TABLE ${TROOT}_digest (
90 /* digest list subscription log */
91 create TABLE ${TROOT}_digest_slog (
92 tai TIMESTAMP DEFAULT now(),
93 address VARCHAR(255) NOT NULL,
94 fromline VARCHAR(255) NOT NULL,
99 /* moderator addresses */
100 create TABLE ${TROOT}_mod (
102 address TEXT NOT NULL
105 /* moderator subscription log */
106 create TABLE ${TROOT}_mod_slog (
107 tai TIMESTAMP DEFAULT now(),
108 address VARCHAR(255) NOT NULL,
109 fromline VARCHAR(255) NOT NULL,
114 /* "allow" address table */
115 create TABLE ${TROOT}_allow (
117 address VARCHAR(255) NOT NULL
120 /* extra address table log */
121 create TABLE ${TROOT}_allow_slog (
122 tai TIMESTAMP DEFAULT now(),
123 address VARCHAR(255) NOT NULL,
124 fromline VARCHAR(255) NOT NULL,
129 /* blacklist address table */
130 create TABLE ${TROOT}_deny (
132 address VARCHAR(255) NOT NULL
135 /* blacklist subscription log */
136 create TABLE ${TROOT}_deny_slog (
138 address VARCHAR(255) NOT NULL,
139 fromline VARCHAR(255) NOT NULL,
144 /* sublist restriction table */
145 /* notuse != 0 => defer message. = 0 => process message */
146 /* no reason for index - will always be small */
147 create TABLE ${TROOT}_name (
149 name VARCHAR(255) NOT NULL,
150 notuse INT4 NOT NULL DEFAULT 0,
151 msgnum_lo INT8 NOT NULL DEFAULT 0,
152 msgnum_hi INT8 NOT NULL DEFAULT 4294967295,
153 hash_lo INT4 NOT NULL DEFAULT 0,
154 hash_hi INT4 NOT NULL DEFAULT 52,
155 domain CHAR(3) NOT NULL DEFAULT '',
156 PRIMARY KEY (listno));
158 /* main list inserts a cookie here. Sublists check it */
159 CREATE TABLE ${TROOT}_cookie (
160 msgnum INT4 NOT NULL,
161 tai TIMESTAMP NOT NULL DEFAULT now(),
162 cookie CHAR(20) NOT NULL,
163 chunk INT4 NOT NULL DEFAULT 0,
164 bodysize INT4 NOT NULL DEFAULT 0,
165 PRIMARY KEY (msgnum));
167 /* main and sublist log here when the message is done */
168 /* done=0 for arrived, done=1 for sent. tai reflects last change, as e.g. */
169 /* done=0 may be overwritten in case first delivery to the list fails. */
170 CREATE TABLE ${TROOT}_mlog (
171 msgnum INT4 NOT NULL,
172 listno INT4 NOT NULL,
173 tai TIMESTAMP DEFAULT now(),
174 subs INT4 NOT NULL DEFAULT 0,
175 done INT4 NOT NULL DEFAULT 0,
176 PRIMARY KEY (listno,msgnum,done));
178 /* digest sublist restriction table */
179 /* notuse != 0 => defer message. = 0 => process message */
180 /* no index, since table unlikely to have >30 or so rows */
181 create TABLE ${TROOT}_digest_name (
183 name VARCHAR(255) NOT NULL,
184 notuse INT4 NOT NULL DEFAULT 0,
185 msgnum_lo INT8 NOT NULL DEFAULT 0,
186 msgnum_hi INT8 NOT NULL DEFAULT 4294967295,
187 hash_lo INT4 NOT NULL DEFAULT 0,
188 hash_hi INT4 NOT NULL DEFAULT 52,
189 domain CHAR(3) NOT NULL DEFAULT '',
190 PRIMARY KEY (listno));
192 /* ezmlm-get when creating a digests inserts a cookie here. Sublists check it*/
193 CREATE TABLE ${TROOT}_digest_cookie (
194 msgnum INT4 NOT NULL,
195 tai TIMESTAMP NOT NULL DEFAULT now(),
196 cookie CHAR(20) NOT NULL,
197 chunk INT4 NOT NULL DEFAULT 0,
198 bodysize INT4 NOT NULL DEFAULT 0,
199 PRIMARY KEY (msgnum));
201 /* ezmlm-get and digest sublists log here when the message is done */
202 /* done=0 for arrived, done=1 for sent. tai reflects last change */
203 CREATE TABLE ${TROOT}_digest_mlog (
204 msgnum INT4 NOT NULL,
205 listno INT4 NOT NULL,
206 tai TIMESTAMP DEFAULT now(),
207 subs INT4 NOT NULL DEFAULT 0,
208 done INT4 NOT NULL DEFAULT 0,
209 PRIMARY KEY (listno,msgnum,done));