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