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