1 /* local and remote users have profiles */
4 id integer auto_increment primary key comment 'unique identifier',
5 nickname varchar(64) not null comment 'nickname or username',
6 fullname varchar(255) comment 'display name',
7 profileurl varchar(255) comment 'URL, cached so we dont regenerate',
8 homepage varchar(255) comment 'identifying URL',
9 bio varchar(140) comment 'descriptive biography',
10 location varchar(255) comment 'physical location',
11 created datetime not null comment 'date this record was created',
12 modified timestamp comment 'date this record was modified',
14 index profile_nickname_idx (nickname),
15 FULLTEXT(nickname, fullname, location, bio, homepage)
16 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
19 profile_id integer not null comment 'foreign key to profile table' references profile (id),
20 original boolean default false comment 'uploaded by user or generated?',
21 width integer not null comment 'image width',
22 height integer not null comment 'image height',
23 mediatype varchar(32) not null comment 'file type',
24 filename varchar(255) null comment 'local filename, if local',
25 url varchar(255) unique key comment 'avatar location',
26 created datetime not null comment 'date this record was created',
27 modified timestamp comment 'date this record was modified',
29 constraint primary key (profile_id, width, height),
30 index avatar_profile_id_idx (profile_id)
31 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
33 create table sms_carrier (
34 id integer primary key comment 'primary key for SMS carrier',
35 name varchar(64) unique key comment 'name of the carrier',
36 email_pattern varchar(255) not null comment 'sprintf pattern for making an email address from a phone number',
37 created datetime not null comment 'date this record was created',
38 modified timestamp comment 'date this record was modified'
39 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
44 id integer primary key comment 'foreign key to profile table' references profile (id),
45 nickname varchar(64) unique key comment 'nickname or username, duped in profile',
46 password varchar(255) comment 'salted password, can be null for OpenID users',
47 email varchar(255) unique key comment 'email address for password recovery etc.',
48 incomingemail varchar(255) unique key comment 'email address for post-by-email',
49 emailnotifysub tinyint default 1 comment 'Notify by email of subscriptions',
50 emailnotifyfav tinyint default 1 comment 'Notify by email of favorites',
51 emailnotifynudge tinyint default 1 comment 'Notify by email of nudges',
52 emailnotifymsg tinyint default 1 comment 'Notify by email of direct messages',
53 emailnotifyattn tinyint default 1 comment 'Notify by email of @-replies',
54 emailmicroid tinyint default 1 comment 'whether to publish email microid',
55 language varchar(50) comment 'preferred language',
56 timezone varchar(50) comment 'timezone',
57 emailpost tinyint default 1 comment 'Post by email',
58 jabber varchar(255) unique key comment 'jabber ID for notices',
59 jabbernotify tinyint default 0 comment 'whether to send notices to jabber',
60 jabberreplies tinyint default 0 comment 'whether to send notices to jabber on replies',
61 jabbermicroid tinyint default 1 comment 'whether to publish xmpp microid',
62 updatefrompresence tinyint default 0 comment 'whether to record updates from Jabber presence notices',
63 sms varchar(64) unique key comment 'sms phone number',
64 carrier integer comment 'foreign key to sms_carrier' references sms_carrier (id),
65 smsnotify tinyint default 0 comment 'whether to send notices to SMS',
66 smsreplies tinyint default 0 comment 'whether to send notices to SMS on replies',
67 smsemail varchar(255) comment 'built from sms and carrier',
68 uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
69 autosubscribe tinyint default 0 comment 'automatically subscribe to users who subscribe to us',
70 urlshorteningservice varchar(50) default 'ur1.ca' comment 'service to use for auto-shortening URLs',
71 inboxed tinyint default 0 comment 'has an inbox been created for this user?',
72 created datetime not null comment 'date this record was created',
73 modified timestamp comment 'date this record was modified',
75 index user_smsemail_idx (smsemail)
76 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
80 create table remote_profile (
81 id integer primary key comment 'foreign key to profile table' references profile (id),
82 uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
83 postnoticeurl varchar(255) comment 'URL we use for posting notices',
84 updateprofileurl varchar(255) comment 'URL we use for updates to this profile',
85 created datetime not null comment 'date this record was created',
86 modified timestamp comment 'date this record was modified'
87 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
89 create table subscription (
90 subscriber integer not null comment 'profile listening',
91 subscribed integer not null comment 'profile being listened to',
92 jabber tinyint default 1 comment 'deliver jabber messages',
93 sms tinyint default 1 comment 'deliver sms messages',
94 token varchar(255) comment 'authorization token',
95 secret varchar(255) comment 'token secret',
96 created datetime not null comment 'date this record was created',
97 modified timestamp comment 'date this record was modified',
99 constraint primary key (subscriber, subscribed),
100 index subscription_subscriber_idx (subscriber),
101 index subscription_subscribed_idx (subscribed),
102 index subscription_token_idx (token)
103 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
105 create table notice (
106 id integer auto_increment primary key comment 'unique identifier',
107 profile_id integer not null comment 'who made the update' references profile (id),
108 uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
109 content varchar(140) comment 'update content',
110 rendered text comment 'HTML version of the content',
111 url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)',
112 created datetime not null comment 'date this record was created',
113 modified timestamp comment 'date this record was modified',
114 reply_to integer comment 'notice replied to (usually a guess)' references notice (id),
115 is_local tinyint default 0 comment 'notice was generated by a user',
116 source varchar(32) comment 'source of comment, like "web", "im", or "clientname"',
118 index notice_profile_id_idx (profile_id),
119 index notice_created_idx (created),
120 index notice_replyto_idx (reply_to),
122 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
124 create table notice_source (
125 code varchar(32) primary key not null comment 'source code',
126 name varchar(255) not null comment 'name of the source',
127 url varchar(255) not null comment 'url to link to',
128 created datetime not null comment 'date this record was created',
129 modified timestamp comment 'date this record was modified'
130 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
133 notice_id integer not null comment 'notice that is the reply' references notice (id),
134 profile_id integer not null comment 'profile replied to' references profile (id),
135 modified timestamp not null comment 'date this record was modified',
136 replied_id integer comment 'notice replied to (not used, see notice.reply_to)',
138 constraint primary key (notice_id, profile_id),
139 index reply_notice_id_idx (notice_id),
140 index reply_profile_id_idx (profile_id),
141 index reply_replied_id_idx (replied_id)
143 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
146 notice_id integer not null comment 'notice that is the favorite' references notice (id),
147 user_id integer not null comment 'user who likes this notice' references user (id),
148 modified timestamp not null comment 'date this record was modified',
150 constraint primary key (notice_id, user_id),
151 index fave_notice_id_idx (notice_id),
152 index fave_user_id_idx (user_id),
153 index fave_modified_idx (modified)
155 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
157 /* tables for OAuth */
159 create table consumer (
160 consumer_key varchar(255) primary key comment 'unique identifier, root URL',
161 seed char(32) not null comment 'seed for new tokens by this consumer',
163 created datetime not null comment 'date this record was created',
164 modified timestamp comment 'date this record was modified'
165 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
168 consumer_key varchar(255) not null comment 'unique identifier, root URL' references consumer (consumer_key),
169 tok char(32) not null comment 'identifying value',
170 secret char(32) not null comment 'secret value',
171 type tinyint not null default 0 comment 'request or access',
172 state tinyint default 0 comment 'for requests, 0 = initial, 1 = authorized, 2 = used',
174 created datetime not null comment 'date this record was created',
175 modified timestamp comment 'date this record was modified',
177 constraint primary key (consumer_key, tok)
178 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
181 consumer_key varchar(255) not null comment 'unique identifier, root URL',
182 tok char(32) null comment 'buggy old value, ignored',
183 nonce char(32) not null comment 'nonce',
184 ts datetime not null comment 'timestamp sent',
186 created datetime not null comment 'date this record was created',
187 modified timestamp comment 'date this record was modified',
189 constraint primary key (consumer_key, ts, nonce)
190 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
192 /* One-to-many relationship of user to openid_url */
194 create table user_openid (
195 canonical varchar(255) primary key comment 'Canonical true URL',
196 display varchar(255) not null unique key comment 'URL for viewing, may be different from canonical',
197 user_id integer not null comment 'user owning this URL' references user (id),
198 created datetime not null comment 'date this record was created',
199 modified timestamp comment 'date this record was modified',
201 index user_openid_user_id_idx (user_id)
202 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
204 /* These are used by JanRain OpenID library */
206 create table oid_associations (
208 handle VARCHAR(255) character set latin1,
212 assoc_type VARCHAR(64),
213 PRIMARY KEY (server_url(255), handle)
214 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
216 create table oid_nonces (
217 server_url VARCHAR(2047),
220 UNIQUE (server_url(255), timestamp, salt)
221 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
223 create table confirm_address (
224 code varchar(32) not null primary key comment 'good random code',
225 user_id integer not null comment 'user who requested confirmation' references user (id),
226 address varchar(255) not null comment 'address (email, Jabber, SMS, etc.)',
227 address_extra varchar(255) not null comment 'carrier ID, for SMS',
228 address_type varchar(8) not null comment 'address type ("email", "jabber", "sms")',
229 claimed datetime comment 'date this was claimed for queueing',
230 sent datetime comment 'date this was sent for queueing',
231 modified timestamp comment 'date this record was modified'
232 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
234 create table remember_me (
235 code varchar(32) not null primary key comment 'good random code',
236 user_id integer not null comment 'user who is logged in' references user (id),
237 modified timestamp comment 'date this record was modified'
238 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
240 create table queue_item (
242 notice_id integer not null comment 'notice queued' references notice (id),
243 transport varchar(8) not null comment 'queue for what? "email", "jabber", "sms", "irc", ...',
244 created datetime not null comment 'date this record was created',
245 claimed datetime comment 'date this item was claimed',
247 constraint primary key (notice_id, transport),
248 index queue_item_created_idx (created)
250 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
253 create table notice_tag (
254 tag varchar( 64 ) not null comment 'hash tag associated with this notice',
255 notice_id integer not null comment 'notice tagged' references notice (id),
256 created datetime not null comment 'date this record was created',
258 constraint primary key (tag, notice_id),
259 index notice_tag_created_idx (created),
260 index notice_tag_notice_id_idx (notice_id)
261 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
263 /* Synching with foreign services */
265 create table foreign_service (
266 id int not null primary key comment 'numeric key for service',
267 name varchar(32) not null unique key comment 'name of the service',
268 description varchar(255) comment 'description',
269 created datetime not null comment 'date this record was created',
270 modified timestamp comment 'date this record was modified'
271 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
273 create table foreign_user (
274 id int not null comment 'unique numeric key on foreign service',
275 service int not null comment 'foreign key to service' references foreign_service(id),
276 uri varchar(255) not null unique key comment 'identifying URI',
277 nickname varchar(255) comment 'nickname on foreign service',
278 created datetime not null comment 'date this record was created',
279 modified timestamp comment 'date this record was modified',
281 constraint primary key (id, service)
282 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
284 create table foreign_link (
285 user_id int comment 'link to user on this system, if exists' references user (id),
286 foreign_id int comment 'link ' references foreign_user(id),
287 service int not null comment 'foreign key to service' references foreign_service(id),
288 credentials varchar(255) comment 'authc credentials, typically a password',
289 noticesync tinyint not null default 1 comment 'notice synchronization, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies',
290 friendsync tinyint not null default 2 comment 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming',
291 profilesync tinyint not null default 1 comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming',
292 last_noticesync datetime default null comment 'last time notices were imported',
293 last_friendsync datetime default null comment 'last time friends were imported',
294 created datetime not null comment 'date this record was created',
295 modified timestamp comment 'date this record was modified',
297 constraint primary key (user_id, foreign_id, service),
298 index foreign_user_user_id_idx (user_id)
299 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
301 create table foreign_subscription (
302 service int not null comment 'service where relationship happens' references foreign_service(id),
303 subscriber int not null comment 'subscriber on foreign service' references foreign_user (id),
304 subscribed int not null comment 'subscribed user' references foreign_user (id),
305 created datetime not null comment 'date this record was created',
307 constraint primary key (service, subscriber, subscribed),
308 index foreign_subscription_subscriber_idx (subscriber),
309 index foreign_subscription_subscribed_idx (subscribed)
310 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
312 create table invitation (
313 code varchar(32) not null primary key comment 'random code for an invitation',
314 user_id int not null comment 'who sent the invitation' references user (id),
315 address varchar(255) not null comment 'invitation sent to',
316 address_type varchar(8) not null comment 'address type ("email", "jabber", "sms")',
317 created datetime not null comment 'date this record was created',
319 index invitation_address_idx (address, address_type),
320 index invitation_user_id_idx (user_id)
321 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
323 create table message (
324 id integer auto_increment primary key comment 'unique identifier',
325 uri varchar(255) unique key comment 'universally unique identifier',
326 from_profile integer not null comment 'who the message is from' references profile (id),
327 to_profile integer not null comment 'who the message is to' references profile (id),
328 content varchar(140) comment 'message content',
329 rendered text comment 'HTML version of the content',
330 url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)',
331 created datetime not null comment 'date this record was created',
332 modified timestamp comment 'date this record was modified',
333 source varchar(32) comment 'source of comment, like "web", "im", or "clientname"',
335 index message_from_idx (from_profile),
336 index message_to_idx (to_profile),
337 index message_created_idx (created)
338 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
340 create table notice_inbox (
341 user_id integer not null comment 'user receiving the message' references user (id),
342 notice_id integer not null comment 'notice received' references notice (id),
343 created datetime not null comment 'date the notice was created',
344 source tinyint default 1 comment 'reason it is in the inbox, 1=subscription',
346 constraint primary key (user_id, notice_id),
347 index notice_inbox_notice_id_idx (notice_id)
348 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
350 create table profile_tag (
351 tagger integer not null comment 'user making the tag' references user (id),
352 tagged integer not null comment 'profile tagged' references profile (id),
353 tag varchar(64) not null comment 'hash tag associated with this notice',
354 modified timestamp comment 'date the tag was added',
356 constraint primary key (tagger, tagged, tag),
357 index profile_tag_modified_idx (modified),
358 index profile_tag_tagger_tag_idx (tagger, tag),
359 index profile_tag_tagged_idx (tagged)
360 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
362 create table profile_block (
363 blocker integer not null comment 'user making the block' references user (id),
364 blocked integer not null comment 'profile that is blocked' references profile (id),
365 modified timestamp comment 'date of blocking',
367 constraint primary key (blocker, blocked)
369 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
371 create table user_group (
372 id integer auto_increment primary key comment 'unique identifier',
374 nickname varchar(64) unique key comment 'nickname for addressing',
375 fullname varchar(255) comment 'display name',
376 homepage varchar(255) comment 'URL, cached so we dont regenerate',
377 description varchar(140) comment 'descriptive biography',
378 location varchar(255) comment 'related physical location, if any',
380 original_logo varchar(255) comment 'original size logo',
381 homepage_logo varchar(255) comment 'homepage (profile) size logo',
382 stream_logo varchar(255) comment 'stream-sized logo',
383 mini_logo varchar(255) comment 'mini logo',
385 created datetime not null comment 'date this record was created',
386 modified timestamp comment 'date this record was modified',
388 index user_group_nickname_idx (nickname)
390 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
392 create table group_member (
393 group_id integer not null comment 'foreign key to user_group' references user_group (id),
394 profile_id integer not null comment 'foreign key to profile table' references profile (id),
395 is_admin boolean default false comment 'is this user an admin?',
397 created datetime not null comment 'date this record was created',
398 modified timestamp comment 'date this record was modified',
400 constraint primary key (group_id, profile_id),
401 index group_member_profile_id_idx (profile_id),
402 index group_member_created_idx (created)
404 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
406 create table related_group (
407 group_id integer not null comment 'foreign key to user_group' references user_group (id),
408 related_group_id integer not null comment 'foreign key to user_group' references user_group (id),
410 created datetime not null comment 'date this record was created',
412 constraint primary key (group_id, related_group_id)
414 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
416 create table group_inbox (
417 group_id integer not null comment 'group receiving the message' references user_group (id),
418 notice_id integer not null comment 'notice received' references notice (id),
419 created datetime not null comment 'date the notice was created',
421 constraint primary key (group_id, notice_id),
422 index group_inbox_created_idx (created)
424 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;