]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - db/statusnet_pg.sql
Merge branch 'testing' 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     seed char(32) not null /* comment 'seed for new tokens by this consumer' */,
191
192     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
193     modified timestamp /* comment 'date this record was modified' */
194 );
195
196 create table token (
197     consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */ references consumer (consumer_key),
198     tok char(32) not null /* comment 'identifying value' */,
199     secret char(32) not null /* comment 'secret value' */,
200     type integer not null default 0 /* comment 'request or access' */,
201     state integer default 0 /* comment 'for requests 0 = initial, 1 = authorized, 2 = used' */,
202
203     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
204     modified timestamp /* comment 'date this record was modified' */,
205
206     primary key (consumer_key, tok)
207 );
208
209 create table nonce (
210     consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */,
211     tok char(32) /* comment 'buggy old value, ignored' */,
212     nonce char(32) null /* comment 'buggy old value, ignored */,
213     ts integer not null /* comment 'timestamp sent' values are epoch, and only used internally */,
214
215     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
216     modified timestamp /* comment 'date this record was modified' */,
217
218     primary key (consumer_key, ts, nonce)
219 );
220
221 create sequence oauth_application_seq;
222 create table oauth_application (
223     id bigint default nextval('oauth_application_seq') primary key /* comment 'unique identifier' */,
224     owner integer not null /* comment 'owner of the application' */ references profile (id),
225     consumer_key varchar(255) not null /* comment 'application consumer key' */ references consumer (consumer_key),
226     name varchar(255) unique not null /* comment 'name of the application' */,
227     description varchar(255) /* comment 'description of the application' */,
228     icon varchar(255) not null /* comment 'application icon' */,
229     source_url varchar(255) /* comment 'application homepage - used for source link' */,
230     organization varchar(255) /* comment 'name of the organization running the application' */,
231     homepage varchar(255) /* comment 'homepage for the organization' */,
232     callback_url varchar(255) /* comment 'url to redirect to after authentication' */,
233     "type" integer default 0 /* comment 'type of app, 1 = browser, 2 = desktop' */,
234     access_type integer default 0 /* comment 'default access type, bit 1 = read, bit 2 = write' */,
235     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
236     modified timestamp /* comment 'date this record was modified' */
237 );
238
239 create table oauth_application_user (
240     profile_id integer not null /* 'user of the application' */ references profile (id),
241     application_id integer not null /* 'id of the application' */ references oauth_application (id),
242     access_type integer default 0 /* 'access type, bit 1 = read, bit 2 = write' */,
243     token varchar(255) /* 'request or access token' */,
244     created timestamp not null default CURRENT_TIMESTAMP /* 'date this record was created' */,
245     modified timestamp /* 'date this record was modified' */,
246     primary key (profile_id, application_id)
247 );
248
249 /* These are used by JanRain OpenID library */
250
251 create table oid_associations (
252     server_url varchar(2047),
253     handle varchar(255),
254     secret bytea,
255     issued integer,
256     lifetime integer,
257     assoc_type varchar(64),
258     primary key (server_url, handle)
259 );
260
261 create table oid_nonces (
262     server_url varchar(2047),
263     "timestamp" integer,
264     salt character(40),
265     unique (server_url, "timestamp", salt)
266 );
267
268 create table confirm_address (
269     code varchar(32) not null primary key /* comment 'good random code' */,
270     user_id integer not null /* comment 'user who requested confirmation' */ references "user" (id),
271     address varchar(255) not null /* comment 'address (email, Jabber, SMS, etc.)' */,
272     address_extra varchar(255) not null default '' /* comment 'carrier ID, for SMS' */,
273     address_type varchar(8) not null /* comment 'address type ("email", "jabber", "sms")' */,
274     claimed timestamp /* comment 'date this was claimed for queueing' */,
275     sent timestamp /* comment 'date this was sent for queueing' */,
276     modified timestamp /* comment 'date this record was modified' */
277 );
278
279 create table remember_me (
280     code varchar(32) not null primary key /* comment 'good random code' */,
281     user_id integer not null /* comment 'user who is logged in' */ references "user" (id),
282     modified timestamp /* comment 'date this record was modified' */
283 );
284
285 create table queue_item (
286
287     notice_id integer not null /* comment 'notice queued' */ references notice (id) ,
288     transport varchar(8) not null /* comment 'queue for what? "email", "jabber", "sms", "irc", ...' */,
289     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
290     claimed timestamp /* comment 'date this item was claimed' */,
291
292     primary key (notice_id, transport)
293
294 );
295 create index queue_item_created_idx on queue_item using btree(created);
296
297 /* Hash tags */
298 create table notice_tag (
299     tag varchar( 64 ) not null /* comment 'hash tag associated with this notice' */,
300     notice_id integer not null /* comment 'notice tagged' */ references notice (id) ,
301     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
302
303     primary key (tag, notice_id)
304 );
305 create index notice_tag_created_idx on notice_tag using btree(created);
306
307 /* Synching with foreign services */
308
309 create table foreign_service (
310      id int not null primary key /* comment 'numeric key for service' */,
311      name varchar(32) not null unique /* comment 'name of the service' */,
312      description varchar(255) /* comment 'description' */,
313      created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
314      modified timestamp /* comment 'date this record was modified' */
315 );
316
317 create table foreign_user (
318      id int not null unique /* comment 'unique numeric key on foreign service' */,
319      service int not null /* comment 'foreign key to service' */ references foreign_service(id) ,
320      uri varchar(255) not null unique /* comment 'identifying URI' */,
321      nickname varchar(255) /* comment 'nickname on foreign service' */,
322      created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
323      modified timestamp /* comment 'date this record was modified' */,
324
325      primary key (id, service)
326 );
327
328 create table foreign_link (
329      user_id int /* comment 'link to user on this system, if exists' */ references "user" (id),
330      foreign_id int /* comment 'link' */ references foreign_user (id),
331      service int not null /* comment 'foreign key to service' */ references foreign_service (id),
332      credentials varchar(255) /* comment 'authc credentials, typically a password' */,
333      noticesync int not null default 1 /* comment 'notice synchronisation, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies' */,
334      friendsync int not null default 2 /* comment 'friend synchronisation, bit 1 = sync outgoing, bit 2 = sync incoming */,
335      profilesync int not null default 1 /* comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming' */,
336      last_noticesync timestamp default null /* comment 'last time notices were imported' */,
337      last_friendsync timestamp default null /* comment 'last time friends were imported' */,
338      created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
339      modified timestamp /* comment 'date this record was modified' */,
340
341      primary key (user_id,foreign_id,service)
342 );
343 create index foreign_user_user_id_idx on foreign_link using btree(user_id);
344
345 create table foreign_subscription (
346      service int not null /* comment 'service where relationship happens' */ references foreign_service(id) ,
347      subscriber int not null /* comment 'subscriber on foreign service' */ ,
348      subscribed int not null /* comment 'subscribed user' */ ,
349      created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
350
351      primary key (service, subscriber, subscribed)
352 );
353 create index foreign_subscription_subscriber_idx on foreign_subscription using btree(subscriber);
354 create index foreign_subscription_subscribed_idx on foreign_subscription using btree(subscribed);
355
356 create table invitation (
357      code varchar(32) not null primary key /* comment 'random code for an invitation' */,
358      user_id int not null /* comment 'who sent the invitation' */ references "user" (id),
359      address varchar(255) not null /* comment 'invitation sent to' */,
360      address_type varchar(8) not null /* comment 'address type ("email", "jabber", "sms") '*/,
361      created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */
362
363 );
364 create index invitation_address_idx on invitation using btree(address,address_type);
365 create index invitation_user_id_idx on invitation using btree(user_id);
366
367 create sequence message_seq;
368 create table message (
369
370     id bigint default nextval('message_seq') primary key /* comment 'unique identifier' */,
371     uri varchar(255) unique /* comment 'universally unique identifier' */,
372     from_profile integer not null /* comment 'who the message is from' */ references profile (id),
373     to_profile integer not null /* comment 'who the message is to' */ references profile (id),
374     content varchar(140) /* comment 'message content' */,
375     rendered text /* comment 'HTML version of the content' */,
376     url varchar(255) /* comment 'URL of any attachment (image, video, bookmark, whatever)' */,
377     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
378     modified timestamp /* comment 'date this record was modified' */,
379     source varchar(32) /* comment 'source of comment, like "web", "im", or "clientname"' */
380
381 );
382 create index message_from_idx on message using btree(from_profile);
383 create index message_to_idx on message using btree(to_profile);
384 create index message_created_idx on message using btree(created);
385
386 create table notice_inbox (
387
388     user_id integer not null /* comment 'user receiving the message' */ references "user" (id),
389     notice_id integer not null /* comment 'notice received' */ references notice (id),
390     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date the notice was created' */,
391     source integer default 1 /* comment 'reason it is in the inbox: 1=subscription' */,
392
393     primary key (user_id, notice_id)
394 );
395 create index notice_inbox_notice_id_idx on notice_inbox using btree(notice_id);
396
397 create table profile_tag (
398    tagger integer not null /* comment 'user making the tag' */ references "user" (id),
399    tagged integer not null /* comment 'profile tagged' */ references profile (id),
400    tag varchar(64) not null /* comment 'hash tag associated with this notice' */,
401    modified timestamp /* comment 'date the tag was added' */,
402
403    primary key (tagger, tagged, tag)
404 );
405 create index profile_tag_modified_idx on profile_tag using btree(modified);
406 create index profile_tag_tagger_tag_idx on profile_tag using btree(tagger,tag);
407
408 create table profile_block (
409
410    blocker integer not null /* comment 'user making the block' */ references "user" (id),
411    blocked integer not null /* comment 'profile that is blocked' */ references profile (id),
412    modified timestamp /* comment 'date of blocking' */,
413
414    primary key (blocker, blocked)
415
416 );
417
418 create sequence user_group_seq;
419 create table user_group (
420
421     id bigint default nextval('user_group_seq') primary key /* comment 'unique identifier' */,
422
423     nickname varchar(64) unique /* comment 'nickname for addressing' */,
424     fullname varchar(255) /* comment 'display name' */,
425     homepage varchar(255) /* comment 'URL, cached so we dont regenerate' */,
426     description varchar(140) /* comment 'descriptive biography' */,
427     location varchar(255) /* comment 'related physical location, if any' */,
428
429     original_logo varchar(255) /* comment 'original size logo' */,
430     homepage_logo varchar(255) /* comment 'homepage (profile) size logo' */,
431     stream_logo varchar(255) /* comment 'stream-sized logo' */,
432     mini_logo varchar(255) /* comment 'mini logo' */,
433     design_id integer /*comment 'id of a design' */ references design(id),
434
435     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
436     modified timestamp /* comment 'date this record was modified' */
437
438 );
439 create index user_group_nickname_idx on user_group using btree(nickname);
440
441 create table group_member (
442
443     group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id),
444     profile_id integer not null /* comment 'foreign key to profile table' */ references profile (id),
445     is_admin integer default 0 /* comment 'is this user an admin?' */,
446
447     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
448     modified timestamp /* comment 'date this record was modified' */,
449
450     primary key (group_id, profile_id)
451 );
452
453 create table related_group (
454
455     group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id) ,
456     related_group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id),
457
458     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
459
460     primary key (group_id, related_group_id)
461
462 );
463
464 create table group_inbox (
465     group_id integer not null /* comment 'group receiving the message' references user_group (id) */,
466     notice_id integer not null /* comment 'notice received' references notice (id) */,
467     created timestamp not null default CURRENT_TIMESTAMP /* comment 'date the notice was created' */,
468     primary key (group_id, notice_id)
469 );
470 create index group_inbox_created_idx on group_inbox using btree(created);
471
472 /*attachments and URLs stuff */
473 create sequence file_seq;
474 create table file (
475     id bigint default nextval('file_seq') primary key /* comment 'unique identifier' */,
476     url varchar(255) unique,
477     mimetype varchar(50),
478     size integer,
479     title varchar(255),
480     date integer,
481     protected integer,
482     filename text /* comment 'if a local file, name of the file' */,
483     modified timestamp default CURRENT_TIMESTAMP /* comment 'date this record was modified'*/
484 );
485
486 create sequence file_oembed_seq;
487 create table file_oembed (
488     file_id bigint default nextval('file_oembed_seq') primary key /* comment 'unique identifier' */,
489     version varchar(20),
490     type varchar(20),
491     mimetype varchar(50),
492     provider varchar(50),
493     provider_url varchar(255),
494     width integer,
495     height integer,
496     html text,
497     title varchar(255),
498     author_name varchar(50),
499     author_url varchar(255),
500     url varchar(255)
501 );
502
503 create sequence file_redirection_seq;
504 create table file_redirection (
505     url varchar(255) primary key,
506     file_id bigint,
507     redirections integer,
508     httpcode integer
509 );
510
511 create sequence file_thumbnail_seq;
512 create table file_thumbnail (
513     file_id bigint primary key,
514     url varchar(255) unique,
515     width integer,
516     height integer
517 );
518
519 create sequence file_to_post_seq;
520 create table file_to_post (
521     file_id bigint,
522     post_id bigint,
523
524     primary key (file_id, post_id)
525 );
526
527 create table group_block (
528    group_id integer not null /* comment 'group profile is blocked from' */ references user_group (id),
529    blocked integer not null /* comment 'profile that is blocked' */references profile (id),
530    blocker integer not null /* comment 'user making the block'*/ references "user" (id),
531    modified timestamp /* comment 'date of blocking'*/ ,
532
533    primary key (group_id, blocked)
534 );
535
536 create table group_alias (
537
538    alias varchar(64) /* comment 'additional nickname for the group'*/ ,
539    group_id integer not null /* comment 'group profile is blocked from'*/ references user_group (id),
540    modified timestamp /* comment 'date alias was created'*/,
541    primary key (alias)
542
543 );
544 create index group_alias_group_id_idx on group_alias (group_id);
545
546 create table session (
547
548     id varchar(32) primary key /* comment 'session ID'*/,
549     session_data text /* comment 'session data'*/,
550     created timestamp not null DEFAULT CURRENT_TIMESTAMP /* comment 'date this record was created'*/,
551     modified integer DEFAULT extract(epoch from CURRENT_TIMESTAMP) /* comment 'date this record was modified'*/
552 );
553
554 create index session_modified_idx on session (modified);
555
556 create table deleted_notice (
557
558     id integer primary key /* comment 'identity of notice'*/ ,
559     profile_id integer /* not null comment 'author of the notice'*/,
560     uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI'*/,
561     created timestamp not null  /* comment 'date the notice record was created'*/ ,
562     deleted timestamp not null DEFAULT CURRENT_TIMESTAMP /* comment 'date the notice record was created'*/
563 );
564
565 CREATE index deleted_notice_profile_id_idx on deleted_notice (profile_id);
566
567 /* Textsearch stuff */
568
569 create index textsearch_idx on profile using gist(textsearch);
570 create index noticecontent_idx on notice using gist(to_tsvector('english',content));
571 create trigger textsearchupdate before insert or update on profile for each row
572 execute procedure tsvector_update_trigger(textsearch, 'pg_catalog.english', nickname, fullname, location, bio, homepage);
573
574 create table config (
575
576     section varchar(32) /* comment 'configuration section'*/,
577     setting varchar(32) /* comment 'configuration setting'*/,
578     value varchar(255) /* comment 'configuration value'*/,
579
580     primary key (section, setting)
581
582 );
583
584 create table profile_role (
585
586     profile_id integer not null /* comment 'account having the role'*/ references profile (id),
587     role    varchar(32) not null /* comment 'string representing the role'*/,
588     created timestamp /* not null comment 'date the role was granted'*/,
589
590     primary key (profile_id, role)
591
592 );
593
594 create table location_namespace (
595
596     id integer /*comment 'identity for this namespace'*/,
597     description text /* comment 'description of the namespace'*/ ,
598     created integer not null /*comment 'date the record was created*/ ,
599    /* modified timestamp comment 'date this record was modified',*/
600     primary key (id)
601
602 );
603
604 create table login_token (
605     user_id integer not null /* comment 'user owning this token'*/ references "user" (id),
606     token char(32) not null /* comment 'token useable for logging in'*/,
607     created timestamp not null DEFAULT CURRENT_TIMESTAMP /* comment 'date this record was created'*/,
608     modified timestamp /* comment 'date this record was modified'*/,
609
610     primary key (user_id)
611 );
612
613 create table user_location_prefs (
614     user_id integer not null /* comment 'user who has the preference' */ references "user" (id),
615     share_location integer default 1 /* comment 'Whether to share location data' */,
616     created timestamp not null DEFAULT CURRENT_TIMESTAMP /* comment 'date this record was created' */,
617     modified timestamp /* comment 'date this record was modified' */,
618
619     primary key (user_id)
620 );
621
622 create table inbox (
623
624     user_id integer not null /* comment 'user receiving the notice' */ references "user" (id),
625     notice_ids bytea /* comment 'packed list of notice ids' */,
626
627     primary key (user_id)
628
629 );
630
631 create sequence conversation_seq;
632 create table conversation (
633     id bigint default nextval('conversation_seq') primary key /* comment 'unique identifier' */,
634     uri varchar(225) unique /* comment 'URI of the conversation' */,
635     created timestamp not null DEFAULT CURRENT_TIMESTAMP /* comment 'date this record was created' */,
636     modified timestamp /* comment 'date this record was modified' */
637 );
638
639 create table local_group (
640
641    group_id integer primary key /* comment 'group represented' */ references user_group (id),
642    nickname varchar(64) unique /* comment 'group represented' */,
643
644    created timestamp not null DEFAULT CURRENT_TIMESTAMP /* comment 'date this record was created' */,
645    modified timestamp /* comment 'date this record was modified' */
646
647 );
648