]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - db/statusnet_pg.sql
added missing columns in notice table
[quix0rs-gnu-social.git] / db / statusnet_pg.sql
1 /* local and remote users have profiles */
2 BEGIN;
3
4 create sequence profile_seq;
5 create table profile (
6     id bigint default nextval('profile_seq') primary key /* comment 'unique identifier' */,
7     nickname varchar(64) not null /* comment 'nickname or username' */,
8     fullname varchar(255) /* comment 'display name' */,
9     profileurl varchar(255) /* comment 'URL, cached so we dont regenerate' */,
10     homepage varchar(255) /* comment 'identifying URL' */,
11     bio varchar(140) /* comment 'descriptive biography' */,
12     location varchar(255) /* comment 'physical location' */,
13     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
14     modified timestamp /* comment 'date this record was modified' */,
15
16     textsearch tsvector
17 );
18 create index profile_nickname_idx on profile using btree(nickname);
19
20 create table avatar (
21     profile_id integer not null /* comment 'foreign key to profile table' */ references profile (id) ,
22     original integer default 0 /* comment 'uploaded by user or generated?' */,
23     width integer not null /* comment 'image width' */,
24     height integer not null /* comment 'image height' */,
25     mediatype varchar(32) not null /* comment 'file type' */,
26     filename varchar(255) null /* comment 'local filename, if local' */,
27     url varchar(255) unique /* comment 'avatar location' */,
28     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
29     modified timestamp /* comment 'date this record was modified' */,
30
31     primary key(profile_id, width, height)
32 );
33 create index avatar_profile_id_idx on avatar using btree(profile_id);
34
35 create sequence sms_carrier_seq;
36 create table sms_carrier (
37     id bigint default nextval('sms_carrier_seq') primary key /* comment 'primary key for SMS carrier' */,
38     name varchar(64) unique /* comment 'name of the carrier' */,
39     email_pattern varchar(255) not null /* comment 'sprintf pattern for making an email address from a phone number' */,
40     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
41     modified timestamp /* comment 'date this record was modified ' */
42 );
43
44 create sequence design_seq;
45 create table design (
46     id bigint default nextval('design_seq') /* comment 'design ID'*/,
47     backgroundcolor integer /* comment 'main background color'*/ ,
48     contentcolor integer /*comment 'content area background color'*/ ,
49     sidebarcolor integer /*comment 'sidebar background color'*/ ,
50     textcolor integer /*comment 'text color'*/ ,
51     linkcolor integer /*comment 'link color'*/,
52     backgroundimage varchar(255) /*comment 'background image, if any'*/,
53     disposition int default 1 /*comment 'bit 1 = hide background image, bit 2 = display background image, bit 4 = tile background image'*/,
54     primary key (id)
55 );
56
57 /* local users */
58
59 create table "user" (
60     id integer primary key /* comment 'foreign key to profile table' */ references profile (id) ,
61     nickname varchar(64) unique /* comment 'nickname or username, duped in profile' */,
62     password varchar(255) /* comment 'salted password, can be null for OpenID users' */,
63     email varchar(255) unique /* comment 'email address for password recovery etc.' */,
64     incomingemail varchar(255) unique /* comment 'email address for post-by-email' */,
65     emailnotifysub integer default 1 /* comment 'Notify by email of subscriptions' */,
66     emailnotifyfav integer default 1 /* comment 'Notify by email of favorites' */,
67     emailnotifynudge integer default 1 /* comment 'Notify by email of nudges' */,
68     emailnotifymsg integer default 1 /* comment 'Notify by email of direct messages' */,
69     emailnotifyattn integer default 1 /* command 'Notify by email of @-replies' */, 
70     emailmicroid integer default 1 /* comment 'whether to publish email microid' */,
71     language varchar(50) /* comment 'preferred language' */,
72     timezone varchar(50) /* comment 'timezone' */,
73     emailpost integer default 1 /* comment 'Post by email' */,
74     jabber varchar(255) unique /* comment 'jabber ID for notices' */,
75     jabbernotify integer default 0 /* comment 'whether to send notices to jabber' */,
76     jabberreplies integer default 0 /* comment 'whether to send notices to jabber on replies' */,
77     jabbermicroid integer default 1 /* comment 'whether to publish xmpp microid' */,
78     updatefrompresence integer default 0 /* comment 'whether to record updates from Jabber presence notices' */,
79     sms varchar(64) unique /* comment 'sms phone number' */,
80     carrier integer /* comment 'foreign key to sms_carrier' */ references sms_carrier (id) ,
81     smsnotify integer default 0 /* comment 'whether to send notices to SMS' */,
82     smsreplies integer default 0 /* comment 'whether to send notices to SMS on replies' */,
83     smsemail varchar(255) /* comment 'built from sms and carrier' */,
84     uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,
85     autosubscribe integer default 0 /* comment 'automatically subscribe to users who subscribe to us' */,
86     urlshorteningservice varchar(50) default 'ur1.ca' /* comment 'service to use for auto-shortening URLs' */,
87     inboxed integer default 0 /* comment 'has an inbox been created for this user?' */, 
88     design_id integer /* comment 'id of a design' */references design(id),
89     viewdesigns integer default 1 /* comment 'whether to view user-provided designs'*/,
90     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
91     modified timestamp /* comment 'date this record was modified' */
92
93 );
94 create index user_smsemail_idx on "user" using btree(smsemail);
95
96 /* remote people */
97
98 create table remote_profile (
99     id integer primary key /* comment 'foreign key to profile table' */ references profile (id) ,
100     uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,
101     postnoticeurl varchar(255) /* comment 'URL we use for posting notices' */,
102     updateprofileurl varchar(255) /* comment 'URL we use for updates to this profile' */,
103     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
104     modified timestamp /* comment 'date this record was modified' */
105 );
106
107 create table subscription (
108     subscriber integer not null /* comment 'profile listening' */,
109     subscribed integer not null /* comment 'profile being listened to' */,
110     jabber integer default 1 /* comment 'deliver jabber messages' */,
111     sms integer default 1 /* comment 'deliver sms messages' */,
112     token varchar(255) /* comment 'authorization token' */,
113     secret varchar(255) /* comment 'token secret' */,
114     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
115     modified timestamp /* comment 'date this record was modified' */,
116
117     primary key (subscriber, subscribed)
118 );
119 create index subscription_subscriber_idx on subscription using btree(subscriber,created);
120 create index subscription_subscribed_idx on subscription using btree(subscribed,created);
121
122 create sequence notice_seq;
123 create table notice (
124
125     id bigint default nextval('notice_seq') primary key /* comment 'unique identifier' */,
126     profile_id integer not null /* comment 'who made the update' */ references profile (id) ,
127     uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,
128     content varchar(140) /* comment 'update content' */,
129     rendered text /* comment 'HTML version of the content' */,
130     url varchar(255) /* comment 'URL of any attachment (image, video, bookmark, whatever)' */,
131     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
132     modified timestamp /* comment 'date this record was modified' */,
133     reply_to integer /* comment 'notice replied to (usually a guess)' */ references notice (id) ,
134     is_local integer default 0 /* comment 'notice was generated by a user' */,
135     source varchar(32) /* comment 'source of comment, like "web", "im", or "clientname"' */,
136     conversation integer /*id of root notice in this conversation' */ references notice (id),
137     lat decimal(10,7) /* comment 'latitude'*/ ,
138     lon decimal(10,7) /* comment 'longitude'*/ ,
139     location_id integer /* comment 'location id if possible'*/ ,
140     location_ns integer /* comment 'namespace for location'*/
141 /*    FULLTEXT(content) */
142 );
143
144 create index notice_profile_id_idx on notice using btree(profile_id,created,id);
145 create index notice_created_idx on notice using btree(created);
146
147 create table notice_source (
148      code varchar(32) primary key not null /* comment 'source code' */,
149      name varchar(255) not null /* comment 'name of the source' */,
150      url varchar(255) not null /* comment 'url to link to' */,
151      created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
152      modified timestamp /* comment 'date this record was modified' */
153 );
154
155 create table reply (
156
157     notice_id integer not null /* comment 'notice that is the reply' */ references notice (id) ,
158     profile_id integer not null /* comment 'profile replied to' */ references profile (id) ,
159     modified timestamp /* comment 'date this record was modified' */,
160     replied_id integer /* comment 'notice replied to (not used, see notice.reply_to)' */,
161
162     primary key (notice_id, profile_id)
163
164 );
165 create index reply_notice_id_idx on reply using btree(notice_id);
166 create index reply_profile_id_idx on reply using btree(profile_id);
167 create index reply_replied_id_idx on reply using btree(replied_id);
168
169 create table fave (
170
171     notice_id integer not null /* comment 'notice that is the favorite' */ references notice (id),
172     user_id integer not null /* comment 'user who likes this notice' */ references "user" (id) ,
173     modified timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was modified' */,
174     primary key (notice_id, user_id)
175
176 );
177 create index fave_notice_id_idx on fave using btree(notice_id);
178 create index fave_user_id_idx on fave using btree(user_id,modified);
179 create index fave_modified_idx on fave using btree(modified);
180
181 /* tables for OAuth */
182
183 create table consumer (
184     consumer_key varchar(255) primary key /* comment 'unique identifier, root URL' */,
185     seed char(32) not null /* comment 'seed for new tokens by this consumer' */,
186
187     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
188     modified timestamp /* comment 'date this record was modified' */
189 );
190
191 create table token (
192     consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */ references consumer (consumer_key),
193     tok char(32) not null /* comment 'identifying value' */,
194     secret char(32) not null /* comment 'secret value' */,
195     type integer not null default 0 /* comment 'request or access' */,
196     state integer default 0 /* comment 'for requests 0 = initial, 1 = authorized, 2 = used' */,
197
198     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
199     modified timestamp /* comment 'date this record was modified' */,
200
201     primary key (consumer_key, tok)
202 );
203
204 create table nonce (
205     consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */,
206     tok char(32) /* comment 'buggy old value, ignored' */,
207     nonce char(32) null /* comment 'buggy old value, ignored */,
208     ts integer not null /* comment 'timestamp sent' values are epoch, and only used internally */,
209
210     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
211     modified timestamp /* comment 'date this record was modified' */,
212
213     primary key (consumer_key, ts, nonce)
214 );
215
216 /* One-to-many relationship of user to openid_url */
217
218 create table user_openid (
219     canonical varchar(255) primary key /* comment 'Canonical true URL' */,
220     display varchar(255) not null unique /* comment 'URL for viewing, may be different from canonical' */,
221     user_id integer not null /* comment 'user owning this URL' */ references "user" (id) ,
222     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
223     modified timestamp /* comment 'date this record was modified' */
224
225 );
226 create index user_openid_user_id_idx on user_openid using btree(user_id);
227
228 /* These are used by JanRain OpenID library */
229
230 create table oid_associations (
231     server_url varchar(2047),
232     handle varchar(255),
233     secret bytea,
234     issued integer,
235     lifetime integer,
236     assoc_type varchar(64),
237     primary key (server_url, handle)
238 );
239
240 create table oid_nonces (
241     server_url varchar(2047),
242     "timestamp" integer,
243     salt character(40),
244     unique (server_url, "timestamp", salt)
245 );
246
247 create table confirm_address (
248     code varchar(32) not null primary key /* comment 'good random code' */,
249     user_id integer not null /* comment 'user who requested confirmation' */ references "user" (id),
250     address varchar(255) not null /* comment 'address (email, Jabber, SMS, etc.)' */,
251     address_extra varchar(255) not null default '' /* comment 'carrier ID, for SMS' */,
252     address_type varchar(8) not null /* comment 'address type ("email", "jabber", "sms")' */,
253     claimed timestamp /* comment 'date this was claimed for queueing' */,
254     sent timestamp /* comment 'date this was sent for queueing' */,
255     modified timestamp /* comment 'date this record was modified' */
256 );
257
258 create table remember_me (
259     code varchar(32) not null primary key /* comment 'good random code' */,
260     user_id integer not null /* comment 'user who is logged in' */ references "user" (id),
261     modified timestamp /* comment 'date this record was modified' */
262 );
263
264 create table queue_item (
265
266     notice_id integer not null /* comment 'notice queued' */ references notice (id) ,
267     transport varchar(8) not null /* comment 'queue for what? "email", "jabber", "sms", "irc", ...' */,
268     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
269     claimed timestamp /* comment 'date this item was claimed' */,
270
271     primary key (notice_id, transport)
272
273 );
274 create index queue_item_created_idx on queue_item using btree(created);
275
276 /* Hash tags */
277 create table notice_tag (
278     tag varchar( 64 ) not null /* comment 'hash tag associated with this notice' */,
279     notice_id integer not null /* comment 'notice tagged' */ references notice (id) ,
280     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
281
282     primary key (tag, notice_id)
283 );
284 create index notice_tag_created_idx on notice_tag using btree(created);
285
286 /* Synching with foreign services */
287
288 create table foreign_service (
289      id int not null primary key /* comment 'numeric key for service' */,
290      name varchar(32) not null unique /* comment 'name of the service' */,
291      description varchar(255) /* comment 'description' */,
292      created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
293      modified timestamp /* comment 'date this record was modified' */
294 );
295
296 create table foreign_user (
297      id int not null unique /* comment 'unique numeric key on foreign service' */,
298      service int not null /* comment 'foreign key to service' */ references foreign_service(id) ,
299      uri varchar(255) not null unique /* comment 'identifying URI' */,
300      nickname varchar(255) /* comment 'nickname on foreign service' */,
301      created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
302      modified timestamp /* comment 'date this record was modified' */,
303      
304      primary key (id, service)
305 );
306
307 create table foreign_link (
308      user_id int /* comment 'link to user on this system, if exists' */ references "user" (id),
309      foreign_id int /* comment 'link' */ references foreign_user (id),
310      service int not null /* comment 'foreign key to service' */ references foreign_service (id),
311      credentials varchar(255) /* comment 'authc credentials, typically a password' */,
312      noticesync int not null default 1 /* comment 'notice synchronisation, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies' */,
313      friendsync int not null default 2 /* comment 'friend synchronisation, bit 1 = sync outgoing, bit 2 = sync incoming */, 
314      profilesync int not null default 1 /* comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming' */,
315      last_noticesync timestamp default null /* comment 'last time notices were imported' */,
316      last_friendsync timestamp default null /* comment 'last time friends were imported' */,
317      created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
318      modified timestamp /* comment 'date this record was modified' */,
319
320      primary key (user_id,foreign_id,service)
321 );
322 create index foreign_user_user_id_idx on foreign_link using btree(user_id);
323
324 create table foreign_subscription (
325      service int not null /* comment 'service where relationship happens' */ references foreign_service(id) ,
326      subscriber int not null /* comment 'subscriber on foreign service' */ ,
327      subscribed int not null /* comment 'subscribed user' */ ,
328      created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
329      
330      primary key (service, subscriber, subscribed)
331 );
332 create index foreign_subscription_subscriber_idx on foreign_subscription using btree(subscriber);
333 create index foreign_subscription_subscribed_idx on foreign_subscription using btree(subscribed);
334
335 create table invitation (
336      code varchar(32) not null primary key /* comment 'random code for an invitation' */,
337      user_id int not null /* comment 'who sent the invitation' */ references "user" (id),
338      address varchar(255) not null /* comment 'invitation sent to' */,
339      address_type varchar(8) not null /* comment 'address type ("email", "jabber", "sms") '*/,
340      created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */
341
342 );
343 create index invitation_address_idx on invitation using btree(address,address_type);
344 create index invitation_user_id_idx on invitation using btree(user_id);
345
346 create sequence message_seq;
347 create table message (
348
349     id bigint default nextval('message_seq') primary key /* comment 'unique identifier' */,
350     uri varchar(255) unique /* comment 'universally unique identifier' */,
351     from_profile integer not null /* comment 'who the message is from' */ references profile (id),
352     to_profile integer not null /* comment 'who the message is to' */ references profile (id),
353     content varchar(140) /* comment 'message content' */,
354     rendered text /* comment 'HTML version of the content' */,
355     url varchar(255) /* comment 'URL of any attachment (image, video, bookmark, whatever)' */,
356     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
357     modified timestamp /* comment 'date this record was modified' */,
358     source varchar(32) /* comment 'source of comment, like "web", "im", or "clientname"' */
359     
360 );
361 create index message_from_idx on message using btree(from_profile);
362 create index message_to_idx on message using btree(to_profile);
363 create index message_created_idx on message using btree(created);
364
365 create table notice_inbox (
366
367     user_id integer not null /* comment 'user receiving the message' */ references "user" (id),
368     notice_id integer not null /* comment 'notice received' */ references notice (id),
369     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date the notice was created' */,
370     source integer default 1 /* comment 'reason it is in the inbox: 1=subscription' */,
371
372     primary key (user_id, notice_id)
373 );
374 create index notice_inbox_notice_id_idx on notice_inbox using btree(notice_id);
375
376 create table profile_tag (
377    tagger integer not null /* comment 'user making the tag' */ references "user" (id),
378    tagged integer not null /* comment 'profile tagged' */ references profile (id),
379    tag varchar(64) not null /* comment 'hash tag associated with this notice' */,
380    modified timestamp /* comment 'date the tag was added' */,
381
382    primary key (tagger, tagged, tag)
383 );
384 create index profile_tag_modified_idx on profile_tag using btree(modified);
385 create index profile_tag_tagger_tag_idx on profile_tag using btree(tagger,tag);
386
387 create table profile_block (
388
389    blocker integer not null /* comment 'user making the block' */ references "user" (id),
390    blocked integer not null /* comment 'profile that is blocked' */ references profile (id),
391    modified timestamp /* comment 'date of blocking' */,
392
393    primary key (blocker, blocked)
394
395 );
396
397 create sequence user_group_seq;
398 create table user_group (
399
400     id bigint default nextval('user_group_seq') primary key /* comment 'unique identifier' */,
401
402     nickname varchar(64) unique /* comment 'nickname for addressing' */,
403     fullname varchar(255) /* comment 'display name' */,
404     homepage varchar(255) /* comment 'URL, cached so we dont regenerate' */,
405     description varchar(140) /* comment 'descriptive biography' */,
406     location varchar(255) /* comment 'related physical location, if any' */,
407
408     original_logo varchar(255) /* comment 'original size logo' */,
409     homepage_logo varchar(255) /* comment 'homepage (profile) size logo' */,
410     stream_logo varchar(255) /* comment 'stream-sized logo' */,
411     mini_logo varchar(255) /* comment 'mini logo' */,
412     design_id integer /*comment 'id of a design' */ references design(id),
413
414
415     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
416     modified timestamp /* comment 'date this record was modified' */
417
418 );
419 create index user_group_nickname_idx on user_group using btree(nickname);
420
421 create table group_member (
422
423     group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id),
424     profile_id integer not null /* comment 'foreign key to profile table' */ references profile (id),
425     is_admin integer default 0 /* comment 'is this user an admin?' */,
426
427     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
428     modified timestamp /* comment 'date this record was modified' */,
429
430     primary key (group_id, profile_id)
431 );
432
433 create table related_group (
434
435     group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id) ,
436     related_group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id),
437
438     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
439
440     primary key (group_id, related_group_id)
441
442 );
443
444 create table group_inbox (
445     group_id integer not null /* comment 'group receiving the message' references user_group (id) */,
446     notice_id integer not null /* comment 'notice received' references notice (id) */,
447     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date the notice was created' */,
448     primary key (group_id, notice_id)
449 );
450 create index group_inbox_created_idx on group_inbox using btree(created);
451
452
453 /*attachments and URLs stuff */
454 create sequence file_seq;
455 create table file (
456     id bigint default nextval('file_seq') primary key /* comment 'unique identifier' */,
457     url varchar(255) unique, 
458     mimetype varchar(50), 
459     size integer, 
460     title varchar(255), 
461     date integer, 
462     protected integer,
463     filename text /* comment 'if a local file, name of the file' */,
464     modified timestamp default CURRENT_TIMESTAMP /* comment 'date this record was modified'*/
465 );
466
467 create sequence file_oembed_seq;
468 create table file_oembed (
469     file_id bigint default nextval('file_oembed_seq') primary key /* comment 'unique identifier' */,
470     version varchar(20),
471     type varchar(20),
472     mimetype varchar(50), 
473     provider varchar(50),
474     provider_url varchar(255),
475     width integer,
476     height integer,
477     html text,
478     title varchar(255),
479     author_name varchar(50), 
480     author_url varchar(255), 
481     url varchar(255) 
482 );
483
484 create sequence file_redirection_seq;
485 create table file_redirection (
486     url varchar(255) primary key, 
487     file_id bigint, 
488     redirections integer, 
489     httpcode integer
490 );
491
492 create sequence file_thumbnail_seq;
493 create table file_thumbnail (
494     file_id bigint primary key, 
495     url varchar(255) unique, 
496     width integer, 
497     height integer 
498 );
499
500 create sequence file_to_post_seq;
501 create table file_to_post (
502     file_id bigint, 
503     post_id bigint, 
504
505     primary key (file_id, post_id)
506 );
507
508 create table group_block (
509    group_id integer not null /* comment 'group profile is blocked from' */ references user_group (id),
510    blocked integer not null /* comment 'profile that is blocked' */references profile (id),
511    blocker integer not null /* comment 'user making the block'*/ references "user" (id),
512    modified timestamp /* comment 'date of blocking'*/ ,
513
514    primary key (group_id, blocked)
515 );
516
517 create table group_alias (
518
519    alias varchar(64) /* comment 'additional nickname for the group'*/ ,
520    group_id integer not null /* comment 'group profile is blocked from'*/ references user_group (id),
521    modified timestamp /* comment 'date alias was created'*/,
522    primary key (alias)
523
524 );
525 create index group_alias_group_id_idx on group_alias (group_id);
526
527 create table session (
528
529     id varchar(32) primary key /* comment 'session ID'*/,
530     session_data text /* comment 'session data'*/,
531     created timestamp not null DEFAULT CURRENT_TIMESTAMP /* comment 'date this record was created'*/,
532     modified integer DEFAULT extract(epoch from CURRENT_TIMESTAMP) /* comment 'date this record was modified'*/ 
533 );
534
535 create index session_modified_idx on session (modified);
536
537 create table deleted_notice (
538
539     id integer primary key /* comment 'identity of notice'*/ ,
540     profile_id integer /* not null comment 'author of the notice'*/,
541     uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI'*/,
542     created timestamp not null  /* comment 'date the notice record was created'*/ ,
543     deleted timestamp not null DEFAULT CURRENT_TIMESTAMP /* comment 'date the notice record was created'*/
544 );
545
546 CREATE index deleted_notice_profile_id_idx on deleted_notice (profile_id);
547
548
549 /* Textsearch stuff */
550
551 create index textsearch_idx on profile using gist(textsearch);
552 create index noticecontent_idx on notice using gist(to_tsvector('english',content));
553 create trigger textsearchupdate before insert or update on profile for each row
554 execute procedure tsvector_update_trigger(textsearch, 'pg_catalog.english', nickname, fullname, location, bio, homepage);
555
556
557 create table config (
558
559     section varchar(32) /* comment 'configuration section'*/,
560     setting varchar(32) /* comment 'configuration setting'*/,
561     value varchar(255) /* comment 'configuration value'*/,
562
563     primary key (section, setting)
564
565 );
566
567 create table profile_role (
568
569     profile_id integer not null /* comment 'account having the role'*/ references profile (id),
570     role    varchar(32) not null /* comment 'string representing the role'*/,
571     created timestamp /* not null comment 'date the role was granted'*/,
572
573     primary key (profile_id, role)
574
575 );
576
577 create table login_token (
578     user_id integer not null /* comment 'user owning this token'*/ references "user" (id),
579     token char(32) not null /* comment 'token useable for logging in'*/,
580     created timestamp not null DEFAULT CURRENT_TIMESTAMP /* comment 'date this record was created'*/,
581     modified timestamp /* comment 'date this record was modified'*/,
582
583     primary key (user_id)
584 );
585
586 ROLLBACK;