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