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