1 /* local and remote users have profiles */
\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
17 create index profile_nickname_idx on profile using btree(nickname);
\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
30 primary key(profile_id, width, height)
\r
32 create index avatar_profile_id_idx on avatar using btree(profile_id);
\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
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
78 create index user_smsemail_idx on "user" using btree(smsemail);
\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
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
101 primary key (subscriber, subscribed)
\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
106 create sequence notice_seq;
\r
107 create table notice (
\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
121 /* FULLTEXT(content) */
\r
123 create index notice_profile_id_idx on notice using btree(profile_id);
\r
124 create index notice_created_idx on notice using btree(created);
\r
126 create table notice_source (
\r
127 code varchar(32) primary key not null /* comment 'source code' */,
\r
128 name varchar(255) not null /* comment 'name of the source' */,
\r
129 url varchar(255) not null /* comment 'url to link to' */,
\r
130 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
131 modified timestamp /* comment 'date this record was modified' */
\r
134 create table reply (
\r
136 notice_id integer not null /* comment 'notice that is the reply' */ references notice (id) ,
\r
137 profile_id integer not null /* comment 'profile replied to' */ references profile (id) ,
\r
138 modified timestamp /* comment 'date this record was modified' */,
\r
139 replied_id integer /* comment 'notice replied to (not used, see notice.reply_to)' */,
\r
141 primary key (notice_id, profile_id)
\r
144 create index reply_notice_id_idx on reply using btree(notice_id);
\r
145 create index reply_profile_id_idx on reply using btree(profile_id);
\r
146 create index reply_replied_id_idx on reply using btree(replied_id);
\r
148 create table fave (
\r
150 notice_id integer not null /* comment 'notice that is the favorite' */ references notice (id),
\r
151 user_id integer not null /* comment 'user who likes this notice' */ references "user" (id) ,
\r
152 modified timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was modified' */,
\r
153 primary key (notice_id, user_id)
\r
156 create index fave_notice_id_idx on fave using btree(notice_id);
\r
157 create index fave_user_id_idx on fave using btree(user_id);
\r
158 create index fave_modified_idx on fave using btree(modified);
\r
160 /* tables for OAuth */
\r
162 create table consumer (
\r
163 consumer_key varchar(255) primary key /* comment 'unique identifier, root URL' */,
\r
164 seed char(32) not null /* comment 'seed for new tokens by this consumer' */,
\r
166 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
167 modified timestamp /* comment 'date this record was modified' */
\r
170 create table token (
\r
171 consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */ references consumer (consumer_key),
\r
172 tok char(32) not null /* comment 'identifying value' */,
\r
173 secret char(32) not null /* comment 'secret value' */,
\r
174 type integer not null default 0 /* comment 'request or access' */,
\r
175 state integer default 0 /* comment 'for requests; 0 = initial, 1 = authorized, 2 = used' */,
\r
177 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
178 modified timestamp /* comment 'date this record was modified' */,
\r
180 primary key (consumer_key, tok)
\r
183 create table nonce (
\r
184 consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */,
\r
185 tok char(32) not null /* comment 'identifying value' */,
\r
186 nonce char(32) null /* comment 'buggy old value, ignored */,
\r
187 ts integer not null /* comment 'timestamp sent' values are epoch, and only used internally */,
\r
189 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
190 modified timestamp /* comment 'date this record was modified' */,
\r
192 primary key (consumer_key, ts, nonce)
\r
195 /* One-to-many relationship of user to openid_url */
\r
197 create table user_openid (
\r
198 canonical varchar(255) primary key /* comment 'Canonical true URL' */,
\r
199 display varchar(255) not null unique /* comment 'URL for viewing, may be different from canonical' */,
\r
200 user_id integer not null /* comment 'user owning this URL' */ references "user" (id) ,
\r
201 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
202 modified timestamp /* comment 'date this record was modified' */
\r
205 create index user_openid_user_id_idx on user_openid using btree(user_id);
\r
207 /* These are used by JanRain OpenID library */
\r
209 create table oid_associations (
\r
210 server_url varchar(2047),
\r
211 handle varchar(255),
\r
215 assoc_type varchar(64),
\r
216 primary key (server_url, handle)
\r
219 create table oid_nonces (
\r
220 server_url varchar(2047),
\r
221 "timestamp" integer,
\r
222 salt character(40),
\r
223 unique (server_url, "timestamp", salt)
\r
226 create table confirm_address (
\r
227 code varchar(32) not null primary key /* comment 'good random code' */,
\r
228 user_id integer not null /* comment 'user who requested confirmation' */ references "user" (id),
\r
229 address varchar(255) not null /* comment 'address (email, Jabber, SMS, etc.)' */,
\r
230 address_extra varchar(255) not null default '' /* comment 'carrier ID, for SMS' */,
\r
231 address_type varchar(8) not null /* comment 'address type ("email", "jabber", "sms")' */,
\r
232 claimed timestamp /* comment 'date this was claimed for queueing' */,
\r
233 sent timestamp /* comment 'date this was sent for queueing' */,
\r
234 modified timestamp /* comment 'date this record was modified' */
\r
237 create table remember_me (
\r
238 code varchar(32) not null primary key /* comment 'good random code' */,
\r
239 user_id integer not null /* comment 'user who is logged in' */ references "user" (id),
\r
240 modified timestamp /* comment 'date this record was modified' */
\r
243 create table queue_item (
\r
245 notice_id integer not null /* comment 'notice queued' */ references notice (id) ,
\r
246 transport varchar(8) not null /* comment 'queue for what? "email", "jabber", "sms", "irc", ...' */,
\r
247 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
248 claimed timestamp /* comment 'date this item was claimed' */,
\r
250 primary key (notice_id, transport)
\r
253 create index queue_item_created_idx on queue_item using btree(created);
\r
256 create table notice_tag (
\r
257 tag varchar( 64 ) not null /* comment 'hash tag associated with this notice' */,
\r
258 notice_id integer not null /* comment 'notice tagged' */ references notice (id) ,
\r
259 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
261 primary key (tag, notice_id)
\r
263 create index notice_tag_created_idx on notice_tag using btree(created);
\r
265 /* Synching with foreign services */
\r
267 create table foreign_service (
\r
268 id int not null primary key /* comment 'numeric key for service' */,
\r
269 name varchar(32) not null unique /* comment 'name of the service' */,
\r
270 description varchar(255) /* comment 'description' */,
\r
271 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
272 modified timestamp /* comment 'date this record was modified' */
\r
275 create table foreign_user (
\r
276 id int not null unique /* comment 'unique numeric key on foreign service' */,
\r
277 service int not null /* comment 'foreign key to service' */ references foreign_service(id) ,
\r
278 uri varchar(255) not null unique /* comment 'identifying URI' */,
\r
279 nickname varchar(255) /* comment 'nickname on foreign service' */,
\r
280 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
281 modified timestamp /* comment 'date this record was modified' */,
\r
283 primary key (id, service)
\r
286 create table foreign_link (
\r
287 user_id int /* comment 'link to user on this system, if exists' */ references "user" (id),
\r
288 foreign_id int /* comment 'link' */ references foreign_user (id),
\r
289 service int not null /* comment 'foreign key to service' */ references foreign_service (id),
\r
290 credentials varchar(255) /* comment 'authc credentials, typically a password' */,
\r
291 noticesync int not null default 1 /* comment 'notice synchronisation, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies' */,
\r
292 friendsync int not null default 2 /* comment 'friend synchronisation, bit 1 = sync outgoing, bit 2 = sync incoming */,
\r
293 profilesync int not null default 1 /* comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming' */,
\r
294 last_noticesync timestamp default null /* comment 'last time notices were imported' */,
\r
295 last_friendsync timestamp default null /* comment 'last time friends were imported' */,
\r
296 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
297 modified timestamp /* comment 'date this record was modified' */,
\r
299 primary key (user_id,foreign_id,service)
\r
301 create index foreign_user_user_id_idx on foreign_link using btree(user_id);
\r
303 create table foreign_subscription (
\r
304 service int not null /* comment 'service where relationship happens' */ references foreign_service(id) ,
\r
305 subscriber int not null /* comment 'subscriber on foreign service' */ ,
\r
306 subscribed int not null /* comment 'subscribed user' */ ,
\r
307 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
309 primary key (service, subscriber, subscribed)
\r
311 create index foreign_subscription_subscriber_idx on foreign_subscription using btree(subscriber);
\r
312 create index foreign_subscription_subscribed_idx on foreign_subscription using btree(subscribed);
\r
314 create table invitation (
\r
315 code varchar(32) not null primary key /* comment 'random code for an invitation' */,
\r
316 user_id int not null /* comment 'who sent the invitation' */ references "user" (id),
\r
317 address varchar(255) not null /* comment 'invitation sent to' */,
\r
318 address_type varchar(8) not null /* comment 'address type ("email", "jabber", "sms") '*/,
\r
319 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */
\r
322 create index invitation_address_idx on invitation using btree(address,address_type);
\r
323 create index invitation_user_id_idx on invitation using btree(user_id);
\r
325 create sequence message_seq;
\r
326 create table message (
\r
328 id bigint default nextval('message_seq') primary key /* comment 'unique identifier' */,
\r
329 uri varchar(255) unique /* comment 'universally unique identifier' */,
\r
330 from_profile integer not null /* comment 'who the message is from' */ references profile (id),
\r
331 to_profile integer not null /* comment 'who the message is to' */ references profile (id),
\r
332 content varchar(140) /* comment 'message content' */,
\r
333 rendered text /* comment 'HTML version of the content' */,
\r
334 url varchar(255) /* comment 'URL of any attachment (image, video, bookmark, whatever)' */,
\r
335 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
336 modified timestamp /* comment 'date this record was modified' */,
\r
337 source varchar(32) /* comment 'source of comment, like "web", "im", or "clientname"' */
\r
340 create index message_from_idx on message using btree(from_profile);
\r
341 create index message_to_idx on message using btree(to_profile);
\r
342 create index message_created_idx on message using btree(created);
\r
344 create table notice_inbox (
\r
346 user_id integer not null /* comment 'user receiving the message' */ references "user" (id),
\r
347 notice_id integer not null /* comment 'notice received' */ references notice (id),
\r
348 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date the notice was created' */,
\r
349 source integer default 1 /* comment 'reason it is in the inbox; 1=subscription' */,
\r
351 primary key (user_id, notice_id)
\r
353 create index notice_inbox_notice_id_idx on notice_inbox using btree(notice_id);
\r
355 create table profile_tag (
\r
356 tagger integer not null /* comment 'user making the tag' */ references "user" (id),
\r
357 tagged integer not null /* comment 'profile tagged' */ references profile (id),
\r
358 tag varchar(64) not null /* comment 'hash tag associated with this notice' */,
\r
359 modified timestamp /* comment 'date the tag was added' */,
\r
361 primary key (tagger, tagged, tag)
\r
363 create index profile_tag_modified_idx on profile_tag using btree(modified);
\r
364 create index profile_tag_tagger_tag_idx on profile_tag using btree(tagger,tag);
\r
366 create table profile_block (
\r
368 blocker integer not null /* comment 'user making the block' */ references "user" (id),
\r
369 blocked integer not null /* comment 'profile that is blocked' */ references profile (id),
\r
370 modified timestamp /* comment 'date of blocking' */,
\r
372 primary key (blocker, blocked)
\r
376 create sequence user_group_seq;
\r
377 create table user_group (
\r
379 id bigint default nextval('user_group_seq') primary key /* comment 'unique identifier' */,
\r
381 nickname varchar(64) unique /* comment 'nickname for addressing' */,
\r
382 fullname varchar(255) /* comment 'display name' */,
\r
383 homepage varchar(255) /* comment 'URL, cached so we dont regenerate' */,
\r
384 description varchar(140) /* comment 'descriptive biography' */,
\r
385 location varchar(255) /* comment 'related physical location, if any' */,
\r
387 original_logo varchar(255) /* comment 'original size logo' */,
\r
388 homepage_logo varchar(255) /* comment 'homepage (profile) size logo' */,
\r
389 stream_logo varchar(255) /* comment 'stream-sized logo' */,
\r
390 mini_logo varchar(255) /* comment 'mini logo' */,
\r
392 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
393 modified timestamp /* comment 'date this record was modified' */
\r
396 create index user_group_nickname_idx on user_group using btree(nickname);
\r
398 create table group_member (
\r
400 group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id),
\r
401 profile_id integer not null /* comment 'foreign key to profile table' */ references profile (id),
\r
402 is_admin integer default 0 /* comment 'is this user an admin?' */,
\r
404 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
405 modified timestamp /* comment 'date this record was modified' */,
\r
407 primary key (group_id, profile_id)
\r
410 create table related_group (
\r
412 group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id) ,
\r
413 related_group_id integer not null /* comment 'foreign key to user_group' */ references user_group (id),
\r
415 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date this record was created' */,
\r
417 primary key (group_id, related_group_id)
\r
421 create table group_inbox (
\r
422 group_id integer not null /* comment 'group receiving the message' references user_group (id) */,
\r
423 notice_id integer not null /* comment 'notice received' references notice (id) */,
\r
424 created timestamp not null default CURRENT_TIMESTAMP /* comment 'date the notice was created' */,
\r
426 primary key (group_id, notice_id)
\r
428 create index group_inbox_created_idx on group_inbox using btree(created);
\r
431 /*attachments and URLs stuff */
\r
432 create sequence file_seq;
\r
433 create table file (
\r
434 id bigint default nextval('file_seq') primary key /* comment 'unique identifier' */,
\r
435 url varchar(255) unique,
\r
436 mimetype varchar(50),
\r
438 title varchar(255),
\r
440 protected integer(1)
\r
443 create sequence file_oembed_seq;
\r
444 create table file_oembed (
\r
445 id bigint default nextval('file_oembed_seq') primary key /* comment 'unique identifier' */,
\r
446 file_id bigint unique,
\r
447 version varchar(20),
\r
449 provider varchar(50),
\r
450 provider_url varchar(255),
\r
454 title varchar(255),
\r
455 author_name varchar(50),
\r
456 author_url varchar(255),
\r
460 create sequence file_redirection_seq;
\r
461 create table file_redirection (
\r
462 id bigint default nextval('file_redirection_seq') primary key /* comment 'unique identifier' */,
\r
463 url varchar(255) unique,
\r
465 redirections integer,
\r
469 create sequence file_thumbnail_seq;
\r
470 create table file_thumbnail (
\r
471 id bigint default nextval('file_thumbnail_seq') primary key /* comment 'unique identifier' */,
\r
472 file_id bigint unique,
\r
473 url varchar(255) unique,
\r
478 create sequence file_to_post_seq;
\r
479 create table file_to_post (
\r
480 id bigint default nextval('file_to_post_seq') primary key /* comment 'unique identifier' */,
\r
484 unique(file_id, post_id)
\r
488 /* Textsearch stuff */
\r
490 create index textsearch_idx on profile using gist(textsearch);
\r
491 create index noticecontent_idx on notice using gist(to_tsvector('english',content));
\r
492 create trigger textsearchupdate before insert or update on profile for each row
\r
493 execute procedure tsvector_update_trigger(textsearch, 'pg_catalog.english', nickname, fullname, location, bio, homepage);
\r