1 /* local and remote users have profiles */
\r
3 create table profile (
\r
4 id serial primary key /* comment 'unique identifier' */,
\r
5 nickname varchar(64) not null /* comment 'nickname or username' */,
\r
6 fullname varchar(255) /* comment 'display name' */,
\r
7 profileurl varchar(255) /* comment 'URL, cached so we dont regenerate' */,
\r
8 homepage varchar(255) /* comment 'identifying URL' */,
\r
9 bio varchar(140) /* comment 'descriptive biography' */,
\r
10 location varchar(255) /* comment 'physical location' */,
\r
11 created timestamp not null /* comment 'date this record was created' */,
\r
12 modified timestamp /* comment 'date this record was modified' */,
\r
16 create index profile_nickname_idx on profile using btree(nickname);
\r
18 create table avatar (
\r
19 profile_id integer not null /* comment 'foreign key to profile table' */ references profile (id) ,
\r
20 original integer default 0 /* comment 'uploaded by user or generated?' */,
\r
21 width integer not null /* comment 'image width' */,
\r
22 height integer not null /* comment 'image height' */,
\r
23 mediatype varchar(32) not null /* comment 'file type' */,
\r
24 filename varchar(255) null /* comment 'local filename, if local' */,
\r
25 url varchar(255) unique /* comment 'avatar location' */,
\r
26 created timestamp not null /* comment 'date this record was created' */,
\r
27 modified timestamp /* comment 'date this record was modified' */,
\r
29 primary key(profile_id, width, height)
\r
31 create index avatar_profile_id_idx on avatar using btree(profile_id);
\r
33 create table sms_carrier (
\r
34 id serial primary key /* comment 'primary key for SMS carrier' */,
\r
35 name varchar(64) unique /* comment 'name of the carrier' */,
\r
36 email_pattern varchar(255) not null /* comment 'sprintf pattern for making an email address from a phone number' */,
\r
37 created timestamp not null /* comment 'date this record was created' */,
\r
38 modified timestamp /* comment 'date this record was modified ' */
\r
43 create table "user" (
\r
44 id integer primary key /* comment 'foreign key to profile table' */ references profile (id) ,
\r
45 nickname varchar(64) unique /* comment 'nickname or username, duped in profile' */,
\r
46 password varchar(255) /* comment 'salted password, can be null for OpenID users' */,
\r
47 email varchar(255) unique /* comment 'email address for password recovery etc.' */,
\r
48 incomingemail varchar(255) unique /* comment 'email address for post-by-email' */,
\r
49 emailnotifysub integer default 1 /* comment 'Notify by email of subscriptions' */,
\r
50 emailmicroid integer default 1 /* comment 'whether to publish email microid' */,
\r
51 language varchar(50) /* comment 'preferred language' */,
\r
52 timezone varchar(50) /* comment 'timezone' */,
\r
53 emailpost integer default 1 /* comment 'Post by email' */,
\r
54 jabber varchar(255) unique /* comment 'jabber ID for notices' */,
\r
55 jabbernotify integer default 0 /* comment 'whether to send notices to jabber' */,
\r
56 jabberreplies integer default 0 /* comment 'whether to send notices to jabber on replies' */,
\r
57 jabbermicroid integer default 1 /* comment 'whether to publish xmpp microid' */,
\r
58 updatefrompresence integer default 0 /* comment 'whether to record updates from Jabber presence notices' */,
\r
59 sms varchar(64) unique /* comment 'sms phone number' */,
\r
60 carrier integer /* comment 'foreign key to sms_carrier' */ references sms_carrier (id) ,
\r
61 smsnotify integer default 0 /* comment 'whether to send notices to SMS' */,
\r
62 smsreplies integer default 0 /* comment 'whether to send notices to SMS on replies' */,
\r
63 smsemail varchar(255) /* comment 'built from sms and carrier' */,
\r
64 uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,
\r
65 autosubscribe integer default 0 /* comment 'automatically subscribe to users who subscribe to us' */,
\r
66 urlshorteningservice varchar(50) default 'ur1.ca' /* comment 'service to use for auto-shortening URLs' */,
\r
67 created timestamp not null /* comment 'date this record was created' */,
\r
68 modified timestamp /* comment 'date this record was modified' */
\r
71 create index user_smsemail_idx on "user" using btree(smsemail);
\r
75 create table remote_profile (
\r
76 id integer primary key /* comment 'foreign key to profile table' */ references profile (id) ,
\r
77 uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,
\r
78 postnoticeurl varchar(255) /* comment 'URL we use for posting notices' */,
\r
79 updateprofileurl varchar(255) /* comment 'URL we use for updates to this profile' */,
\r
80 created timestamp not null /* comment 'date this record was created' */,
\r
81 modified timestamp /* comment 'date this record was modified' */
\r
84 create table subscription (
\r
85 subscriber integer not null /* comment 'profile listening' */,
\r
86 subscribed integer not null /* comment 'profile being listened to' */,
\r
87 token varchar(255) /* comment 'authorization token' */,
\r
88 secret varchar(255) /* comment 'token secret' */,
\r
89 created timestamp not null /* comment 'date this record was created' */,
\r
90 modified timestamp /* comment 'date this record was modified' */,
\r
92 primary key (subscriber, subscribed)
\r
94 create index subscription_subscriber_idx on subscription using btree(subscriber);
\r
95 create index subscription_subscribed_idx on subscription using btree(subscribed);
\r
97 create table notice (
\r
99 id serial primary key /* comment 'unique identifier' */,
\r
100 profile_id integer not null /* comment 'who made the update' */ references profile (id) ,
\r
101 uri varchar(255) unique /* comment 'universally unique identifier, usually a tag URI' */,
\r
102 content varchar(140) /* comment 'update content' */,
\r
103 rendered text /* comment 'HTML version of the content' */,
\r
104 url varchar(255) /* comment 'URL of any attachment (image, video, bookmark, whatever)' */,
\r
105 created timestamp not null /* comment 'date this record was created' */,
\r
106 modified timestamp /* comment 'date this record was modified' */,
\r
107 reply_to integer /* comment 'notice replied to (usually a guess)' */ references notice (id) ,
\r
108 is_local integer default 0 /* comment 'notice was generated by a user' */,
\r
109 source varchar(32) /* comment 'source of comment, like "web", "im", or "clientname"' */
\r
111 /* FULLTEXT(content) */
\r
113 create index notice_profile_id_idx on notice using btree(profile_id);
\r
114 create index notice_created_idx on notice using btree(created);
\r
116 create table notice_source (
\r
117 code varchar(32) primary key not null /* comment 'source code' */,
\r
118 name varchar(255) not null /* comment 'name of the source' */,
\r
119 url varchar(255) not null /* comment 'url to link to' */,
\r
120 created timestamp not null /* comment 'date this record was created' */,
\r
121 modified timestamp /* comment 'date this record was modified' */
\r
124 create table reply (
\r
126 notice_id integer not null /* comment 'notice that is the reply' */ references notice (id) ,
\r
127 profile_id integer not null /* comment 'profile replied to' */ references profile (id) ,
\r
128 modified timestamp not null default 'now' /* comment 'date this record was modified' */,
\r
129 replied_id integer /* comment 'notice replied to (not used, see notice.reply_to)' */,
\r
131 primary key (notice_id, profile_id)
\r
134 create index reply_notice_id_idx on reply using btree(notice_id);
\r
135 create index reply_profile_id_idx on reply using btree(profile_id);
\r
136 create index reply_replied_id_idx on reply using btree(replied_id);
\r
138 create table fave (
\r
140 notice_id integer not null /* comment 'notice that is the favorite' */ references notice (id),
\r
141 user_id integer not null /* comment 'user who likes this notice' */ references "user" (id) ,
\r
142 modified timestamp not null /* comment 'date this record was modified' */,
\r
144 primary key (notice_id, user_id)
\r
147 create index fave_notice_id_idx on fave using btree(notice_id);
\r
148 create index fave_user_id_idx on fave using btree(user_id);
\r
149 create index fave_modified_idx on fave using btree(modified);
\r
151 /* tables for OAuth */
\r
153 create table consumer (
\r
154 consumer_key varchar(255) primary key /* comment 'unique identifier, root URL' */,
\r
155 seed char(32) not null /* comment 'seed for new tokens by this consumer' */,
\r
157 created timestamp not null /* comment 'date this record was created' */,
\r
158 modified timestamp /* comment 'date this record was modified' */
\r
161 create table token (
\r
162 consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */ references consumer (consumer_key),
\r
163 tok char(32) not null /* comment 'identifying value' */,
\r
164 secret char(32) not null /* comment 'secret value' */,
\r
165 type integer not null default 0 /* comment 'request or access' */,
\r
166 state integer default 0 /* comment 'for requests; 0 = initial, 1 = authorized, 2 = used' */,
\r
168 created timestamp not null /* comment 'date this record was created' */,
\r
169 modified timestamp /* comment 'date this record was modified' */,
\r
171 primary key (consumer_key, tok)
\r
174 create table nonce (
\r
175 consumer_key varchar(255) not null /* comment 'unique identifier, root URL' */,
\r
176 tok char(32) not null /* comment 'identifying value' */,
\r
177 nonce char(32) not null /* comment 'nonce' */,
\r
178 ts timestamp not null /* comment 'timestamp sent' */,
\r
180 created timestamp not null /* comment 'date this record was created' */,
\r
181 modified timestamp /* comment 'date this record was modified' */,
\r
183 primary key (consumer_key, tok, nonce),
\r
184 foreign key (consumer_key, tok) references token (consumer_key, tok)
\r
187 /* One-to-many relationship of user to openid_url */
\r
189 create table user_openid (
\r
190 canonical varchar(255) primary key /* comment 'Canonical true URL' */,
\r
191 display varchar(255) not null unique /* comment 'URL for viewing, may be different from canonical' */,
\r
192 user_id integer not null /* comment 'user owning this URL' */ references "user" (id) ,
\r
193 created timestamp not null /* comment 'date this record was created' */,
\r
194 modified timestamp /* comment 'date this record was modified' */
\r
197 create index user_openid_user_id_idx on user_openid using btree(user_id);
\r
199 /* These are used by JanRain OpenID library */
\r
201 create table oid_associations (
\r
202 server_url varchar(2047),
\r
203 handle varchar(255),
\r
207 assoc_type varchar(64),
\r
208 primary key (server_url, handle)
\r
211 create table oid_nonces (
\r
212 server_url varchar(2047),
\r
213 "timestamp" integer,
\r
214 salt character(40),
\r
215 unique (server_url, "timestamp", salt)
\r
218 create table confirm_address (
\r
219 code varchar(32) not null primary key /* comment 'good random code' */,
\r
220 user_id integer not null /* comment 'user who requested confirmation' */ references "user" (id),
\r
221 address varchar(255) not null /* comment 'address (email, Jabber, SMS, etc.)' */,
\r
222 address_extra varchar(255) not null default '' /* comment 'carrier ID, for SMS' */,
\r
223 address_type varchar(8) not null /* comment 'address type ("email", "jabber", "sms")' */,
\r
224 claimed timestamp /* comment 'date this was claimed for queueing' */,
\r
225 sent timestamp /* comment 'date this was sent for queueing' */,
\r
226 modified timestamp /* comment 'date this record was modified' */
\r
229 create table remember_me (
\r
230 code varchar(32) not null primary key /* comment 'good random code' */,
\r
231 user_id integer not null /* comment 'user who is logged in' */ references "user" (id),
\r
232 modified timestamp /* comment 'date this record was modified' */
\r
235 create table queue_item (
\r
237 notice_id integer not null /* comment 'notice queued' */ references notice (id) ,
\r
238 transport varchar(8) not null /* comment 'queue for what? "email", "jabber", "sms", "irc", ...' */,
\r
239 created timestamp not null /* comment 'date this record was created' */,
\r
240 claimed timestamp /* comment 'date this item was claimed' */,
\r
242 primary key (notice_id, transport)
\r
245 create index queue_item_created_idx on queue_item using btree(created);
\r
248 create table notice_tag (
\r
249 tag varchar( 64 ) not null /* comment 'hash tag associated with this notice' */,
\r
250 notice_id integer not null /* comment 'notice tagged' */ references notice (id) ,
\r
251 created timestamp not null /* comment 'date this record was created' */,
\r
253 primary key (tag, notice_id)
\r
255 create index notice_tag_created_idx on notice_tag using btree(created);
\r
257 /* Synching with foreign services */
\r
259 create table foreign_service (
\r
260 id int not null primary key /* comment 'numeric key for service' */,
\r
261 name varchar(32) not null unique /* comment 'name of the service' */,
\r
262 description varchar(255) /* comment 'description' */,
\r
263 created timestamp not null /* comment 'date this record was created' */,
\r
264 modified timestamp /* comment 'date this record was modified' */
\r
267 create table foreign_user (
\r
268 id int not null /* comment 'unique numeric key on foreign service' */,
\r
269 service int not null /* comment 'foreign key to service' */ references foreign_service(id) ,
\r
270 uri varchar(255) not null unique /* comment 'identifying URI' */,
\r
271 nickname varchar(255) /* comment 'nickname on foreign service' */,
\r
272 user_id int /* comment 'link to user on this system, if exists' */ references "user" (id),
\r
273 credentials varchar(255) /* comment 'authc credentials, typically a password' */,
\r
274 created timestamp not null /* comment 'date this record was created' */,
\r
275 modified timestamp /* comment 'date this record was modified' */,
\r
277 primary key (id, service)
\r
279 create index foreign_user_user_id_idx on foreign_user using btree(user_id);
\r
281 create table foreign_subscription (
\r
282 service int not null /* comment 'service where relationship happens' */ references foreign_service(id) ,
\r
283 subscriber int not null /* comment 'subscriber on foreign service' */ ,
\r
284 subscribed int not null /* comment 'subscribed user' */ ,
\r
285 created timestamp not null /* comment 'date this record was created' */,
\r
287 primary key (service, subscriber, subscribed)
\r
289 create index foreign_subscription_subscriber_idx on foreign_subscription using btree(subscriber);
\r
290 create index foreign_subscription_subscribed_idx on foreign_subscription using btree(subscribed);
\r
292 create table invitation (
\r
293 code varchar(32) not null primary key /* comment 'random code for an invitation' */,
\r
294 user_id int not null /* comment 'who sent the invitation' */ references "user" (id),
\r
295 address varchar(255) not null /* comment 'invitation sent to' */,
\r
296 address_type varchar(8) not null /* comment 'address type ("email", "jabber", "sms") '*/,
\r
297 created timestamp not null /* comment 'date this record was created' */
\r
300 create index invitation_address_idx on invitation using btree(address,address_type);
\r
301 create index invitation_user_id_idx on invitation using btree(user_id);
\r
303 create table message (
\r
305 id serial primary key /* comment 'unique identifier' */,
\r
306 uri varchar(255) unique /* comment 'universally unique identifier' */,
\r
307 from_profile integer not null /* comment 'who the message is from' */ references profile (id),
\r
308 to_profile integer not null /* comment 'who the message is to' */ references profile (id),
\r
309 content varchar(140) /* comment 'message content' */,
\r
310 rendered text /* comment 'HTML version of the content' */,
\r
311 url varchar(255) /* comment 'URL of any attachment (image, video, bookmark, whatever)' */,
\r
312 created timestamp not null /* comment 'date this record was created' */,
\r
313 modified timestamp /* comment 'date this record was modified' */,
\r
314 source varchar(32) /* comment 'source of comment, like "web", "im", or "clientname"' */
\r
317 create index message_from_idx on message using btree(from_profile);
\r
318 create index message_to_idx on message using btree(to_profile);
\r
319 create index message_created_idx on message using btree(created);
\r
321 /* Textsearch stuff */
\r
323 create index textsearch_idx on profile using gist(textsearch);
\r
324 create index noticecontent_idx on notice using gist(to_tsvector('english',content));
\r
325 create trigger textsearchupdate before insert or update on profile for each row
\r
326 execute procedure tsvector_update_trigger(textsearch, 'pg_catalog.english', nickname, fullname, location, bio, homepage);
\r