]> git.imager.perl.org - bse.git/blame - schema/bse.sql
0.13_01 commit
[bse.git] / schema / bse.sql
CommitLineData
41b9d8ec 1-- represents sections, articles
a051492d 2DROP TABLE IF EXISTS article;
41b9d8ec
TC
3CREATE TABLE article (
4 id integer DEFAULT '0' NOT NULL auto_increment,
5
6 -- 0 for the entry page
7 -- -1 for top-level sections (shown in side menu)
8 parentid integer DEFAULT '0' NOT NULL,
9
10 -- the order to display articles in
11 -- used for ordering sibling articles
12 displayOrder integer not NULL default 0,
6e3d2da5 13 title varchar(255) DEFAULT '' NOT NULL,
41b9d8ec
TC
14 titleImage varchar(64) not null,
15 body text NOT NULL,
16
17 -- thumbnail image
18 thumbImage varchar(64) not null default '',
19 thumbWidth integer not null,
20 thumbHeight integer not null,
21
22 -- position of first image for this article
23 imagePos char(2) not null,
24 release datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
25 expire datetime DEFAULT '9999-12-31 23:59:59' NOT NULL,
26 keyword varchar(255),
27
28 -- the template in $TMPLDIR used to generate this as HTML
29 template varchar(127) DEFAULT '' NOT NULL,
30
31 -- a link to the page generated for this article
32 -- if this is blank then no page is generated
33 -- this is combined with the base of the site to get the file
34 -- written to during generation
35 link varchar(64) not null,
36 admin varchar(64) not null,
37
38 -- if there are more child articles than this, display links/summaries
39 -- if the same of fewer, embed the articles
40 -- the template can ignore this
41 threshold integer not null default 3,
42
43 -- the length of summary to display for this article
44 summaryLength smallint(5) unsigned DEFAULT '200' NOT NULL,
45
46 -- the class whose generate() method generates the page
47 generator varchar(20) not null default 'article',
48
49 -- the level of the article, 1 for top-level
50 level smallint not null,
51
52 -- for listed:
53 -- 0 - don't list
54 -- 1 - list everywhere
55 -- 2 - list in sections, but not on the menu
56 listed smallint not null default 1,
57 -- date last modified
58 lastModified date not null,
918735d1
TC
59
60 -- flags specified via the config file
61 -- used by code and templates
62 flags varchar(80) not null default '',
63
331fd099
TC
64 -- custom fields for local usage
65 customDate1 datetime null,
66 customDate2 datetime null,
67
68 customStr1 varchar(255) null,
69 customStr2 varchar(255) null,
70
41b9d8ec
TC
71 PRIMARY KEY (id),
72
73 -- if we keep id in the indexes MySQL will sometimes be able to
74 -- perform a query using _just_ the index, without scanning through
75 -- all our main records with their blobs
76 -- Unfortunately MySQL can only do this on fixed-width columns
77 -- other databases may not need the id in the index, and may also be
78 -- able to handle the variable length columns in the index
79 INDEX article_date_index (release,expire, id),
80 INDEX article_displayOrder_index (displayOrder),
81 INDEX article_parentId_index (parentId),
82 INDEX article_level_index (level, id)
83);
84
85#
86# Table structure for table 'searchindex'
87#
a051492d
TC
88
89DROP TABLE IF EXISTS searchindex;
41b9d8ec
TC
90CREATE TABLE searchindex (
91 id varchar(200) binary DEFAULT '' NOT NULL,
92 -- a comma-separated lists of article and section ids
93 articleIds varchar(255) default '' not null,
94 sectionIds varchar(255) default '' not null,
95 scores varchar(255) default '' not null,
96 PRIMARY KEY (id)
97);
98
99#
100# Table structure for table 'image'
101#
a051492d 102DROP TABLE IF EXISTS image;
41b9d8ec
TC
103CREATE TABLE image (
104 id mediumint(8) unsigned NOT NULL auto_increment,
105 articleId integer not null,
106 image varchar(64) DEFAULT '' NOT NULL,
107 alt varchar(255) DEFAULT '[Image]' NOT NULL,
108 width smallint(5) unsigned,
109 height smallint(5) unsigned,
6dc52c17 110 url varchar(255),
ca9aa2bf 111 displayOrder integer not null default 0,
4772671f 112 name varchar(255) default '' not null,
6dc52c17 113
41b9d8ec
TC
114 PRIMARY KEY (id)
115);
116
117# used for session tracking with Apache::Session::MySQL
a051492d 118DROP TABLE IF EXISTS sessions;
41b9d8ec
TC
119CREATE TABLE sessions (
120 id char(32) not null primary key,
121 a_session text,
122 -- so we can age this table
123 whenChanged timestamp
124);
125
126-- these share data with the article table
a051492d 127DROP TABLE IF EXISTS product;
41b9d8ec
TC
128create table product (
129 -- fkey to article id
130 articleId integer not null,
131
132 summary varchar(255) not null,
133
134 -- number of days it typically takes to supply this item
135 leadTime integer not null default 0,
136
137 -- prices are in cents
138 retailPrice integer not null,
139 wholesalePrice integer,
140
141 -- amount of GST on this item
142 gst integer not null,
6dc52c17
TC
143
144 -- options that can be specified for this product
145 options varchar(255) not null,
41b9d8ec
TC
146
147 primary key(articleId)
148);
149
150-- order is a reserved word
151-- I couldn't think of/find another word here
a051492d 152DROP TABLE IF EXISTS orders;
41b9d8ec
TC
153create table orders (
154 id integer not null auto_increment,
155
156 -- delivery address
157 delivFirstName varchar(127) not null default '',
158 delivLastName varchar(127) not null default '',
159 delivStreet varchar(127) not null default '',
160 delivSuburb varchar(127) not null default '',
161 delivState varchar(40) not null default '',
162 delivPostCode varchar(40) not null default '',
163 delivCountry varchar(127) not null default 'Australia',
164
165 -- billing address
166 billFirstName varchar(127) not null default '',
167 billLastName varchar(127) not null default '',
168 billStreet varchar(127) not null default '',
169 billSuburb varchar(127) not null default '',
170 billState varchar(40) not null default '',
171 billPostCode varchar(40) not null default '',
172 billCountry varchar(127) not null default 'Australia',
173
174 telephone varchar(80) not null default '',
175 facsimile varchar(80) not null default '',
176 emailAddress varchar(255) not null default '',
177
178 -- total price
179 total integer not null,
180 wholesaleTotal integer not null default 0,
181 gst integer not null,
182
183 orderDate datetime not null,
184
185 -- credit card information
186 ccNumberHash varchar(127) not null default '',
187 ccName varchar(127) not null default '',
188 ccExpiryHash varchar(127) not null default '',
189 ccType varchar(30) not null,
190
6dc52c17
TC
191 -- non-zero if the order was filled
192 filled integer not null default 0,
193 whenFilled datetime,
194 whoFilled varchar(40) not null default '',
195
196 -- if the order has been paid for
197 paidFor integer not null default 0,
198 paymentReceipt varchar(40),
199
200 -- hard to guess identifier
201 randomId varchar(40),
202
203 -- order was cancelled
204 cancelled integer not null default 0,
205
edc5d096
TC
206 -- user id of the person who made the order
207 -- an empty string if there's no user
208 userId varchar(40) not null,
209
08123550
TC
210 paymentType integer not null default 0,
211
212 -- intended for custom uses
213 customInt1 integer null,
214 customInt2 integer null,
215 customInt3 integer null,
216 customInt4 integer null,
217 customInt5 integer null,
218
219 customStr1 varchar(255) null,
220 customStr2 varchar(255) null,
221 customStr3 varchar(255) null,
222 customStr4 varchar(255) null,
223 customStr5 varchar(255) null,
224
41b9d8ec 225 primary key (id),
edc5d096
TC
226 index order_cchash(ccNumberHash),
227 index order_userId(userId, orderDate)
41b9d8ec
TC
228);
229
a051492d 230DROP TABLE IF EXISTS order_item;
41b9d8ec
TC
231create table order_item (
232 id integer not null auto_increment,
233 -- foreign key to product
234 productId integer not null,
235
236 -- foreign key to order
237 orderId integer not null,
238
239 -- how many :)
240 units integer not null,
241
242 -- unit prices
243 price integer not null,
244 wholesalePrice integer not null,
245 gst integer not null,
246
6dc52c17
TC
247 -- options (if any) specified on this item in the order
248 options varchar(255) not null,
249
41b9d8ec
TC
250 primary key (id),
251 index order_item_order(orderId, id)
252);
aaf38b76
TC
253
254drop table if exists other_parents;
255create table other_parents (
256 id integer not null auto_increment,
257
258 parentId integer not null,
259 childId integer not null,
260
261 -- order as seen from the parent
262 parentDisplayOrder integer not null,
263 -- order as seen from the child
264 childDisplayOrder integer not null,
265
99ef7979
TC
266 release datetime default '0000-00-00 00:00:00' not null,
267 expire datetime default '9999-12-31 23:59:59' not null,
268
aaf38b76
TC
269 primary key(id),
270 unique (parentId, childId),
99ef7979 271 index (childId, childDisplayOrder)
edc5d096
TC
272);
273
274-- initially we just do paid for files, later we may add unpaid for files
275-- there's some database support here to support unpaid for files
276-- but it won't be implemented yet
277drop table if exists article_files;
278create table article_files (
279 id integer not null auto_increment,
280 articleId integer not null,
281
282 -- the name of the file as displayed
283 displayName varchar(80) not null default '',
284
285 -- the filename as stored in the repository
286 filename varchar(80) not null default '',
287
288 -- how big it is
289 sizeInBytes integer not null,
290
291 -- a description of the file
292 description varchar(255) not null default '',
293
294 -- content type
295 contentType varchar(80) not null default 'application/octet-stream',
296
297 -- used to control the order the files are displayed in
298 displayOrder integer not null,
299
300 -- if non-zero this item is for sale
301 -- it has no public URL and can only be downloaded via a script
302 forSale integer not null default 0,
303
304 -- we try to make the browser download the file rather than display it
305 download integer not null default 0,
306
307 -- when it was uploaded
308 whenUploaded datetime not null,
309
4afdbb1b
TC
310 -- user must be logged in to download this file
311 requireUser integer not null default 0,
312
edc5d096
TC
313 primary key (id)
314);
315
b19047a6
TC
316drop table if exists subscription_types;
317create table subscription_types (
318 id integer not null auto_increment,
319
320 -- name as listed to users on the user options page, and as listed
321 -- on the subscriptions management page
322 name varchar(80) not null,
323
324 -- the default title put into the article, and used for the article title
325 -- field when generating the article
326 title varchar(64) not null,
327
328 -- a description for the subscription
329 -- used on user options page to give more info about a subscription
330 description text not null,
331
332 -- description of the frequency of subscriptions
333 -- eg. "weekly", "Every Monday and Thursday"
334 frequency varchar(127) not null,
335
336 -- keyword field for the generated article
337 keyword varchar(255) not null,
338
339 -- do we archive the email to an article?
340 archive integer not null default 1,
341
342 -- template used when we build the article
343 article_template varchar(127) not null,
344
345 -- one or both of the following template needs to be defined
346 -- if you only define the html template then the email won't be sent
347 -- to users who only accept text emails
348 -- template used for the HTML portion of the email
349 html_template varchar(127) not null,
350
351 -- template used for the text portion of the email
352 text_template varchar(127) not null,
353
354 -- which parent to put the generated article under
355 -- can be 0 to indicate no article is generated
356 parentId integer not null,
357
358 -- the last time this was sent out
359 lastSent datetime not null default '0000-00-00 00:00',
4ef01459
TC
360
361 -- if this is non-zero then the subscription is visible to users
362 visible integer not null default 1,
b19047a6
TC
363
364 primary key (id)
365);
366
367-- which lists users are subscribed to
368drop table if exists subscribed_users;
369create table subscribed_users (
370 id integer not null auto_increment,
371 subId integer not null,
372 userId integer not null,
373 primary key(id),
374 unique (subId, userId)
375);
376
edc5d096
TC
377-- contains web site users
378-- there will be a separate admin users table at some point
379drop table if exists site_users;
380create table site_users (
381 id integer not null auto_increment,
382
383 userId varchar(40) not null,
384 password varchar(40) not null,
35c0719f 385 email varchar(255) not null,
edc5d096
TC
386
387 keepAddress integer not null default 1,
388 whenRegistered datetime not null,
389 lastLogon datetime not null,
390
391 -- used to fill in the checkout form
392 name1 varchar(127),
393 name2 varchar(127),
394 address varchar(127),
395 city varchar(127),
396 state varchar(40),
397 postcode varchar(40),
398 telephone varchar(80),
399 facsimile varchar(80),
400 country varchar(127),
401
402 -- the user wants to receive the site newsletter if any
403 -- this should default to NO
b19047a6 404 -- this is probably ignored for now
edc5d096
TC
405 wantLetter integer not null default 0,
406
b19047a6
TC
407 -- if this is non-zero, we have permission to send email to this
408 -- user
409 confirmed integer not null default 0,
410
411 -- the confirmation message we send to a user includes this value
412 -- in the confirmation url
413 confirmSecret varchar(40) not null default '',
414
415 -- non-zero if we sent a confirmation message
416 waitingForConfirmation integer not null default 0,
417
418 textOnlyMail integer not null,
419
35c0719f 420 title varchar(127),
b19047a6
TC
421 organization varchar(127),
422
423 referral integer,
424 otherReferral varchar(127) not null,
425 prompt integer,
426 otherPrompt varchar(127) not null,
427 profession integer not null,
428 otherProfession varchar(127) not null,
429
15fb10f2
TC
430 previousLogon datetime not null,
431
edc5d096
TC
432 primary key (id),
433 unique (userId)
b19047a6
TC
434);
435
436-- this is used to track email addresses that we've sent subscription
437-- confirmations to
438-- this is used to prevent an attacked creating a few hundred site users
439-- and having the system send confirmation requests to those users
440-- we make sure we only send one confirmation request per 48 hours
441-- and a maximum of 3 unacknowledged confirmation requests
442-- once the 3rd confirmation request is sent we don't send the user
443-- any more requests - ever
444--
445-- each confirmation message also includes a blacklist address the
446-- recipient can use to add themselves to the blacklist
447--
448-- We don't have an unverified mechanism to add users to the blacklist
449-- since someone could use this as a DoS.
450--
451-- Once we receive an acknowledgement from the recipient we remove them
452-- from this table.
453drop table if exists email_requests;
454create table email_requests (
455 -- the table/row classes need this for now
456 id integer not null auto_increment,
457
458 # the actual email address the confirmation was sent to
459 email varchar(127) not null,
460
461 # the genericized email address
462 genEmail varchar(127) not null,
463
464 -- when the last confirmation email was sent
465 lastConfSent datetime not null default '0000-00-00 00:00:00',
466
467 -- how many confirmation messages have been sent
468 unackedConfMsgs integer not null default 0,
469
470 primary key (id),
471 unique (email),
472 unique (genEmail)
473);
474
475-- these are emails that someone has asked not to be subscribed to
476-- any mailing list
477drop table if exists email_blacklist;
478create table email_blacklist (
479 -- the table/row classes need this for now
480 id integer not null auto_increment,
481 email varchar(127) not null,
482
483 -- a short description of why the address was blacklisted
484 why varchar(20) not null,
485
486 primary key (id),
487 unique (email)
caa7299c
TC
488);
489
490drop table if exists admin_base;
491create table admin_base (
492 id integer not null auto_increment,
493 type char not null,
494 primary key (id)
495);
496
497drop table if exists admin_users;
498create table admin_users (
499 base_id integer not null,
500 logon varchar(60) not null,
501 name varchar(255) not null,
502 password varchar(80) not null,
503 perm_map varchar(255) not null,
504 primary key (base_id),
505 unique (logon)
506);
507
508drop table if exists admin_groups;
509create table admin_groups (
510 base_id integer not null,
511 name varchar(80) not null,
512 description varchar(255) not null,
513 perm_map varchar(255) not null,
514 primary key (base_id),
515 unique (name)
516);
517
518drop table if exists admin_membership;
519create table admin_membership (
520 user_id integer not null,
521 group_id integer not null,
522 primary key (user_id, group_id)
523);
524
525drop table if exists admin_perms;
526create table admin_perms (
527 object_id integer not null,
528 admin_id integer not null,
529 perm_map varchar(255),
530 primary key (object_id, admin_id)
531);