]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - db/statusnet.sql
ensure*() functions throw exceptions for errors
[quix0rs-gnu-social.git] / db / statusnet.sql
1 /* local and remote users have profiles */
2
3 create table profile (
4
5     id integer auto_increment primary key comment 'unique identifier',
6     nickname varchar(64) not null comment 'nickname or username',
7     fullname varchar(255) comment 'display name',
8     profileurl varchar(255) comment 'URL, cached so we dont regenerate',
9     homepage varchar(255) comment 'identifying URL',
10     bio text comment 'descriptive biography',
11     location varchar(255) comment 'physical location',
12     lat decimal(10,7) comment 'latitude',
13     lon decimal(10,7) comment 'longitude',
14     location_id integer comment 'location id if possible',
15     location_ns integer comment 'namespace for location',
16
17     created datetime not null comment 'date this record was created',
18     modified timestamp comment 'date this record was modified',
19
20     index profile_nickname_idx (nickname),
21     FULLTEXT(nickname, fullname, location, bio, homepage)
22 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
23
24 create table avatar (
25     profile_id integer not null comment 'foreign key to profile table' references profile (id),
26     original boolean default false comment 'uploaded by user or generated?',
27     width integer not null comment 'image width',
28     height integer not null comment 'image height',
29     mediatype varchar(32) not null comment 'file type',
30     filename varchar(255) null comment 'local filename, if local',
31     url varchar(255) unique key comment 'avatar location',
32     created datetime not null comment 'date this record was created',
33     modified timestamp comment 'date this record was modified',
34
35     constraint primary key (profile_id, width, height),
36     index avatar_profile_id_idx (profile_id)
37 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
38
39 create table sms_carrier (
40     id integer primary key comment 'primary key for SMS carrier',
41     name varchar(64) unique key comment 'name of the carrier',
42     email_pattern varchar(255) not null comment 'sprintf pattern for making an email address from a phone number',
43     created datetime not null comment 'date this record was created',
44     modified timestamp comment 'date this record was modified'
45 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
46
47 /* local users */
48
49 create table user (
50
51     id integer primary key comment 'foreign key to profile table' references profile (id),
52     nickname varchar(64) unique key comment 'nickname or username, duped in profile',
53     password varchar(255) comment 'salted password, can be null for OpenID users',
54     email varchar(255) unique key comment 'email address for password recovery etc.',
55     incomingemail varchar(255) unique key comment 'email address for post-by-email',
56     emailnotifysub tinyint default 1 comment 'Notify by email of subscriptions',
57     emailnotifyfav tinyint default 1 comment 'Notify by email of favorites',
58     emailnotifynudge tinyint default 1 comment 'Notify by email of nudges',
59     emailnotifymsg tinyint default 1 comment 'Notify by email of direct messages',
60     emailnotifyattn tinyint default 1 comment 'Notify by email of @-replies',
61     emailmicroid tinyint default 1 comment 'whether to publish email microid',
62     language varchar(50) comment 'preferred language',
63     timezone varchar(50) comment 'timezone',
64     emailpost tinyint default 1 comment 'Post by email',
65     jabber varchar(255) unique key comment 'jabber ID for notices',
66     jabbernotify tinyint default 0 comment 'whether to send notices to jabber',
67     jabberreplies tinyint default 0 comment 'whether to send notices to jabber on replies',
68     jabbermicroid tinyint default 1 comment 'whether to publish xmpp microid',
69     updatefrompresence tinyint default 0 comment 'whether to record updates from Jabber presence notices',
70     sms varchar(64) unique key comment 'sms phone number',
71     carrier integer comment 'foreign key to sms_carrier' references sms_carrier (id),
72     smsnotify tinyint default 0 comment 'whether to send notices to SMS',
73     smsreplies tinyint default 0 comment 'whether to send notices to SMS on replies',
74     smsemail varchar(255) comment 'built from sms and carrier',
75     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
76     autosubscribe tinyint default 0 comment 'automatically subscribe to users who subscribe to us',
77     urlshorteningservice varchar(50) default 'ur1.ca' comment 'service to use for auto-shortening URLs',
78     inboxed tinyint default 0 comment 'has an inbox been created for this user?',
79     design_id integer comment 'id of a design' references design(id),
80     viewdesigns tinyint default 1 comment 'whether to view user-provided designs',
81
82     created datetime not null comment 'date this record was created',
83     modified timestamp comment 'date this record was modified',
84
85     index user_smsemail_idx (smsemail)
86 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
87
88 /* remote people */
89
90 create table remote_profile (
91     id integer primary key comment 'foreign key to profile table' references profile (id),
92     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
93     postnoticeurl varchar(255) comment 'URL we use for posting notices',
94     updateprofileurl varchar(255) comment 'URL we use for updates to this profile',
95     created datetime not null comment 'date this record was created',
96     modified timestamp comment 'date this record was modified'
97 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
98
99 create table subscription (
100     subscriber integer not null comment 'profile listening',
101     subscribed integer not null comment 'profile being listened to',
102     jabber tinyint default 1 comment 'deliver jabber messages',
103     sms tinyint default 1 comment 'deliver sms messages',
104     token varchar(255) comment 'authorization token',
105     secret varchar(255) comment 'token secret',
106     created datetime not null comment 'date this record was created',
107     modified timestamp comment 'date this record was modified',
108
109     constraint primary key (subscriber, subscribed),
110     index subscription_subscriber_idx (subscriber, created),
111     index subscription_subscribed_idx (subscribed, created),
112     index subscription_token_idx (token)
113 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
114
115 create table notice (
116     id integer auto_increment primary key comment 'unique identifier',
117     profile_id integer not null comment 'who made the update' references profile (id),
118     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
119     content text comment 'update content',
120     rendered text comment 'HTML version of the content',
121     url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)',
122     created datetime not null comment 'date this record was created',
123     modified timestamp comment 'date this record was modified',
124     reply_to integer comment 'notice replied to (usually a guess)' references notice (id),
125     is_local tinyint default 0 comment 'notice was generated by a user',
126     source varchar(32) comment 'source of comment, like "web", "im", or "clientname"',
127     conversation integer comment 'id of root notice in this conversation' references notice (id),
128     lat decimal(10,7) comment 'latitude',
129     lon decimal(10,7) comment 'longitude',
130     location_id integer comment 'location id if possible',
131     location_ns integer comment 'namespace for location',
132     repeat_of integer comment 'notice this is a repeat of' references notice (id),
133
134     -- For public timeline...
135     index notice_created_id_is_local_idx (created,id,is_local),
136
137     -- For profile timelines...
138     index notice_profile_id_idx (profile_id,created,id),
139
140     -- For api/statuses/repeats...
141     index notice_repeat_of_created_id_idx (repeat_of, created, id),
142
143     -- For conversation views
144     index notice_conversation_created_id_idx (conversation, created, id),
145
146     -- Are these needed/used?
147     index notice_replyto_idx (reply_to),
148
149     FULLTEXT(content)
150 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
151
152 create table notice_source (
153      code varchar(32) primary key not null comment 'source code',
154      name varchar(255) not null comment 'name of the source',
155      url varchar(255) not null comment 'url to link to',
156      created datetime not null comment 'date this record was created',
157      modified timestamp comment 'date this record was modified'
158 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
159
160 create table reply (
161     notice_id integer not null comment 'notice that is the reply' references notice (id),
162     profile_id integer not null comment 'profile replied to' references profile (id),
163     modified timestamp not null comment 'date this record was modified',
164     replied_id integer comment 'notice replied to (not used, see notice.reply_to)',
165
166     constraint primary key (notice_id, profile_id),
167     index reply_notice_id_idx (notice_id),
168     index reply_profile_id_idx (profile_id),
169     index reply_replied_id_idx (replied_id),
170
171     -- Needed for sorting reply/mentions timelines
172     index reply_profile_id_modified_notice_id_idx (profile_id, modified, notice_id)
173
174 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
175
176 create table fave (
177     notice_id integer not null comment 'notice that is the favorite' references notice (id),
178     user_id integer not null comment 'user who likes this notice' references user (id),
179     modified timestamp not null comment 'date this record was modified',
180
181     constraint primary key (notice_id, user_id),
182     index fave_notice_id_idx (notice_id),
183     index fave_user_id_idx (user_id,modified),
184     index fave_modified_idx (modified)
185
186 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
187
188 /* tables for OAuth */
189
190 create table consumer (
191     consumer_key varchar(255) primary key comment 'unique identifier, root URL',
192     consumer_secret varchar(255) not null comment 'secret value',
193     seed char(32) not null comment 'seed for new tokens by this consumer',
194
195     created datetime not null comment 'date this record was created',
196     modified timestamp comment 'date this record was modified'
197 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
198
199 create table token (
200     consumer_key varchar(255) not null comment 'unique identifier, root URL' references consumer (consumer_key),
201     tok char(32) not null comment 'identifying value',
202     secret char(32) not null comment 'secret value',
203     type tinyint not null default 0 comment 'request or access',
204     state tinyint default 0 comment 'for requests, 0 = initial, 1 = authorized, 2 = used',
205     verifier varchar(255) comment 'verifier string for OAuth 1.0a',
206     verified_callback varchar(255) comment 'verified callback URL for OAuth 1.0a',
207
208     created datetime not null comment 'date this record was created',
209     modified timestamp comment 'date this record was modified',
210
211     constraint primary key (consumer_key, tok)
212 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
213
214 create table nonce (
215     consumer_key varchar(255) not null comment 'unique identifier, root URL',
216     tok char(32) null comment 'buggy old value, ignored',
217     nonce char(32) not null comment 'nonce',
218     ts datetime not null comment 'timestamp sent',
219
220     created datetime not null comment 'date this record was created',
221     modified timestamp comment 'date this record was modified',
222
223     constraint primary key (consumer_key, ts, nonce)
224 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
225
226 create table oauth_application (
227     id integer auto_increment primary key comment 'unique identifier',
228     owner integer not null comment 'owner of the application' references profile (id),
229     consumer_key varchar(255) not null comment 'application consumer key' references consumer (consumer_key),
230     name varchar(255) not null unique key comment 'name of the application',
231     description varchar(255) comment 'description of the application',
232     icon varchar(255) not null comment 'application icon',
233     source_url varchar(255) comment 'application homepage - used for source link',
234     organization varchar(255) comment 'name of the organization running the application',
235     homepage varchar(255) comment 'homepage for the organization',
236     callback_url varchar(255) comment 'url to redirect to after authentication',
237     type tinyint default 0 comment 'type of app, 1 = browser, 2 = desktop',
238     access_type tinyint default 0 comment 'default access type, bit 1 = read, bit 2 = write',
239     created datetime not null comment 'date this record was created',
240     modified timestamp comment 'date this record was modified'
241 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
242
243 create table oauth_application_user (
244     profile_id integer not null comment 'user of the application' references profile (id),
245     application_id integer not null comment 'id of the application' references oauth_application (id),
246     access_type tinyint default 0 comment 'access type, bit 1 = read, bit 2 = write',
247     token varchar(255) comment 'request or access token',
248     created datetime not null comment 'date this record was created',
249     modified timestamp comment 'date this record was modified',
250     constraint primary key (profile_id, application_id)
251 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
252
253 create table oauth_token_association (
254     profile_id integer not null comment 'user of the application' references profile (id),
255     application_id integer not null comment 'id of the application' references oauth_application (id),
256     token varchar(255) comment 'request or access token',
257     created datetime not null comment 'date this record was created',
258     modified timestamp comment 'date this record was modified',
259     constraint primary key (profile_id, application_id, token)
260 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
261
262 /* These are used by JanRain OpenID library */
263
264 create table oid_associations (
265     server_url BLOB,
266     handle VARCHAR(255) character set latin1,
267     secret BLOB,
268     issued INTEGER,
269     lifetime INTEGER,
270     assoc_type VARCHAR(64),
271     PRIMARY KEY (server_url(255), handle)
272 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
273
274 create table oid_nonces (
275     server_url VARCHAR(2047),
276     timestamp INTEGER,
277     salt CHAR(40),
278     UNIQUE (server_url(255), timestamp, salt)
279 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
280
281 create table confirm_address (
282     code varchar(32) not null primary key comment 'good random code',
283     user_id integer not null comment 'user who requested confirmation' references user (id),
284     address varchar(255) not null comment 'address (email, Jabber, SMS, etc.)',
285     address_extra varchar(255) not null comment 'carrier ID, for SMS',
286     address_type varchar(8) not null comment 'address type ("email", "jabber", "sms")',
287     claimed datetime comment 'date this was claimed for queueing',
288     sent datetime comment 'date this was sent for queueing',
289     modified timestamp comment 'date this record was modified'
290 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
291
292 create table remember_me (
293     code varchar(32) not null primary key comment 'good random code',
294     user_id integer not null comment 'user who is logged in' references user (id),
295     modified timestamp comment 'date this record was modified'
296 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
297
298 create table queue_item (
299     id integer auto_increment primary key comment 'unique identifier',
300     frame blob not null comment 'data: object reference or opaque string',
301     transport varchar(8) not null comment 'queue for what? "email", "jabber", "sms", "irc", ...',
302     created datetime not null comment 'date this record was created',
303     claimed datetime comment 'date this item was claimed',
304
305     index queue_item_created_idx (created)
306
307 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
308
309 /* Hash tags */
310 create table notice_tag (
311     tag varchar( 64 ) not null comment 'hash tag associated with this notice',
312     notice_id integer not null comment 'notice tagged' references notice (id),
313     created datetime not null comment 'date this record was created',
314
315     constraint primary key (tag, notice_id),
316     index notice_tag_created_idx (created),
317     index notice_tag_notice_id_idx (notice_id),
318
319     -- For sorting tag-filtered public timeline
320     index notice_tag_tag_created_notice_id_idx (tag, created, notice_id)
321 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
322
323 /* Synching with foreign services */
324
325 create table foreign_service (
326      id int not null primary key comment 'numeric key for service',
327      name varchar(32) not null unique key comment 'name of the service',
328      description varchar(255) comment 'description',
329      created datetime not null comment 'date this record was created',
330      modified timestamp comment 'date this record was modified'
331 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
332
333 create table foreign_user (
334      id bigint not null comment 'unique numeric key on foreign service',
335      service int not null comment 'foreign key to service' references foreign_service(id),
336      uri varchar(255) not null unique key comment 'identifying URI',
337      nickname varchar(255) comment 'nickname on foreign service',
338      created datetime not null comment 'date this record was created',
339      modified timestamp comment 'date this record was modified',
340
341      constraint primary key (id, service)
342 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
343
344 create table foreign_link (
345      user_id int comment 'link to user on this system, if exists' references user (id),
346      foreign_id bigint unsigned comment 'link to user on foreign service, if exists' references foreign_user(id),
347      service int not null comment 'foreign key to service' references foreign_service(id),
348      credentials varchar(255) comment 'authc credentials, typically a password',
349      noticesync tinyint not null default 1 comment 'notice synchronization, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies',
350      friendsync tinyint not null default 2 comment 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming',
351      profilesync tinyint not null default 1 comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming',
352      last_noticesync datetime default null comment 'last time notices were imported',
353      last_friendsync datetime default null comment 'last time friends were imported',
354      created datetime not null comment 'date this record was created',
355      modified timestamp comment 'date this record was modified',
356
357      constraint primary key (user_id, foreign_id, service),
358      index foreign_user_user_id_idx (user_id)
359 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
360
361 create table foreign_subscription (
362      service int not null comment 'service where relationship happens' references foreign_service(id),
363      subscriber int not null comment 'subscriber on foreign service' references foreign_user (id),
364      subscribed int not null comment 'subscribed user' references foreign_user (id),
365      created datetime not null comment 'date this record was created',
366
367      constraint primary key (service, subscriber, subscribed),
368      index foreign_subscription_subscriber_idx (subscriber),
369      index foreign_subscription_subscribed_idx (subscribed)
370 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
371
372 create table invitation (
373      code varchar(32) not null primary key comment 'random code for an invitation',
374      user_id int not null comment 'who sent the invitation' references user (id),
375      address varchar(255) not null comment 'invitation sent to',
376      address_type varchar(8) not null comment 'address type ("email", "jabber", "sms")',
377      created datetime not null comment 'date this record was created',
378
379      index invitation_address_idx (address, address_type),
380      index invitation_user_id_idx (user_id)
381 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
382
383 create table message (
384     id integer auto_increment primary key comment 'unique identifier',
385     uri varchar(255) unique key comment 'universally unique identifier',
386     from_profile integer not null comment 'who the message is from' references profile (id),
387     to_profile integer not null comment 'who the message is to' references profile (id),
388     content text comment 'message content',
389     rendered text comment 'HTML version of the content',
390     url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)',
391     created datetime not null comment 'date this record was created',
392     modified timestamp comment 'date this record was modified',
393     source varchar(32) comment 'source of comment, like "web", "im", or "clientname"',
394
395     index message_from_idx (from_profile),
396     index message_to_idx (to_profile),
397     index message_created_idx (created)
398 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
399
400 create table notice_inbox (
401     user_id integer not null comment 'user receiving the message' references user (id),
402     notice_id integer not null comment 'notice received' references notice (id),
403     created datetime not null comment 'date the notice was created',
404     source tinyint default 1 comment 'reason it is in the inbox, 1=subscription',
405
406     constraint primary key (user_id, notice_id),
407     index notice_inbox_notice_id_idx (notice_id)
408 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
409
410 create table profile_tag (
411    tagger integer not null comment 'user making the tag' references user (id),
412    tagged integer not null comment 'profile tagged' references profile (id),
413    tag varchar(64) not null comment 'hash tag associated with this notice',
414    modified timestamp comment 'date the tag was added',
415
416    constraint primary key (tagger, tagged, tag),
417    index profile_tag_modified_idx (modified),
418    index profile_tag_tagger_tag_idx (tagger, tag),
419    index profile_tag_tagged_idx (tagged)
420 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
421
422 create table profile_block (
423    blocker integer not null comment 'user making the block' references user (id),
424    blocked integer not null comment 'profile that is blocked' references profile (id),
425    modified timestamp comment 'date of blocking',
426
427    constraint primary key (blocker, blocked)
428
429 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
430
431 create table user_group (
432     id integer auto_increment primary key comment 'unique identifier',
433
434     nickname varchar(64) comment 'nickname for addressing',
435     fullname varchar(255) comment 'display name',
436     homepage varchar(255) comment 'URL, cached so we dont regenerate',
437     description text comment 'group description',
438     location varchar(255) comment 'related physical location, if any',
439
440     original_logo varchar(255) comment 'original size logo',
441     homepage_logo varchar(255) comment 'homepage (profile) size logo',
442     stream_logo varchar(255) comment 'stream-sized logo',
443     mini_logo varchar(255) comment 'mini logo',
444     design_id integer comment 'id of a design' references design(id),
445
446     created datetime not null comment 'date this record was created',
447     modified timestamp comment 'date this record was modified',
448
449     uri varchar(255) unique key comment 'universal identifier',
450     mainpage varchar(255) comment 'page for group info to link to',
451
452     index user_group_nickname_idx (nickname)
453
454 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
455
456 create table group_member (
457     group_id integer not null comment 'foreign key to user_group' references user_group (id),
458     profile_id integer not null comment 'foreign key to profile table' references profile (id),
459     is_admin boolean default false comment 'is this user an admin?',
460
461     created datetime not null comment 'date this record was created',
462     modified timestamp comment 'date this record was modified',
463
464     constraint primary key (group_id, profile_id),
465     index group_member_profile_id_idx (profile_id),
466     index group_member_created_idx (created),
467
468     -- To pull up a list of someone's groups in order joined
469     index group_member_profile_id_created_idx (profile_id, created)
470
471 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
472
473 create table related_group (
474     group_id integer not null comment 'foreign key to user_group' references user_group (id),
475     related_group_id integer not null comment 'foreign key to user_group' references user_group (id),
476
477     created datetime not null comment 'date this record was created',
478
479     constraint primary key (group_id, related_group_id)
480
481 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
482
483 create table group_inbox (
484     group_id integer not null comment 'group receiving the message' references user_group (id),
485     notice_id integer not null comment 'notice received' references notice (id),
486     created datetime not null comment 'date the notice was created',
487
488     constraint primary key (group_id, notice_id),
489     index group_inbox_created_idx (created),
490     index group_inbox_notice_id_idx (notice_id),
491
492     -- Needed for sorting group messages by timestamp
493     index group_inbox_group_id_created_notice_id_idx (group_id, created, notice_id)
494
495 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
496
497 create table file (
498
499     id integer primary key auto_increment,
500     url varchar(255) comment 'destination URL after following redirections',
501     mimetype varchar(50) comment 'mime type of resource',
502     size integer comment 'size of resource when available',
503     title varchar(255) comment 'title of resource when available',
504     date integer(11) comment 'date of resource according to http query',
505     protected integer(1) comment 'true when URL is private (needs login)',
506     filename varchar(255) comment 'if a local file, name of the file',
507
508     modified timestamp comment 'date this record was modified',
509
510     unique(url)
511 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
512
513 create table file_oembed (
514     file_id integer primary key comment 'oEmbed for that URL/file' references file (id),
515     version varchar(20) comment 'oEmbed spec. version',
516     type varchar(20) comment 'oEmbed type: photo, video, link, rich',
517     mimetype varchar(50) comment 'mime type of resource',
518     provider varchar(50) comment 'name of this oEmbed provider',
519     provider_url varchar(255) comment 'URL of this oEmbed provider',
520     width integer comment 'width of oEmbed resource when available',
521     height integer comment 'height of oEmbed resource when available',
522     html text comment 'html representation of this oEmbed resource when applicable',
523     title varchar(255) comment 'title of oEmbed resource when available',
524     author_name varchar(50) comment 'author name for this oEmbed resource',
525     author_url varchar(255) comment 'author URL for this oEmbed resource',
526     url varchar(255) comment 'URL for this oEmbed resource when applicable (photo, link)',
527     modified timestamp comment 'date this record was modified'
528
529 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
530
531 create table file_redirection (
532
533     url varchar(255) primary key comment 'short URL (or any other kind of redirect) for file (id)',
534     file_id integer comment 'short URL for what URL/file' references file (id),
535     redirections integer comment 'redirect count',
536     httpcode integer comment 'HTTP status code (20x, 30x, etc.)',
537     modified timestamp comment 'date this record was modified'
538
539 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
540
541 create table file_thumbnail (
542
543     file_id integer primary key comment 'thumbnail for what URL/file' references file (id),
544     url varchar(255) comment 'URL of thumbnail',
545     width integer comment 'width of thumbnail',
546     height integer comment 'height of thumbnail',
547     modified timestamp comment 'date this record was modified',
548
549     unique(url)
550 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
551
552 create table file_to_post (
553
554     file_id integer comment 'id of URL/file' references file (id),
555     post_id integer comment 'id of the notice it belongs to' references notice (id),
556     modified timestamp comment 'date this record was modified',
557
558     constraint primary key (file_id, post_id),
559     index post_id_idx (post_id)
560
561 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
562
563 create table design (
564     id integer primary key auto_increment comment 'design ID',
565     backgroundcolor integer comment 'main background color',
566     contentcolor integer comment 'content area background color',
567     sidebarcolor integer comment 'sidebar background color',
568     textcolor integer comment 'text color',
569     linkcolor integer comment 'link color',
570     backgroundimage varchar(255) comment 'background image, if any',
571     disposition tinyint default 1 comment 'bit 1 = hide background image, bit 2 = display background image, bit 4 = tile background image'
572 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
573
574 create table group_block (
575    group_id integer not null comment 'group profile is blocked from' references user_group (id),
576    blocked integer not null comment 'profile that is blocked' references profile (id),
577    blocker integer not null comment 'user making the block' references user (id),
578    modified timestamp comment 'date of blocking',
579
580    constraint primary key (group_id, blocked)
581
582 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
583
584 create table group_alias (
585
586    alias varchar(64) primary key comment 'additional nickname for the group',
587    group_id integer not null comment 'group profile is blocked from' references user_group (id),
588    modified timestamp comment 'date alias was created',
589
590    index group_alias_group_id_idx (group_id)
591
592 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
593
594 create table session (
595
596     id varchar(32) primary key comment 'session ID',
597     session_data text comment 'session data',
598     created datetime not null comment 'date this record was created',
599     modified timestamp comment 'date this record was modified',
600
601     index session_modified_idx (modified)
602
603 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
604
605 create table deleted_notice (
606
607     id integer primary key comment 'identity of notice',
608     profile_id integer not null comment 'author of the notice',
609     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
610     created datetime not null comment 'date the notice record was created',
611     deleted datetime not null comment 'date the notice record was created',
612
613     index deleted_notice_profile_id_idx (profile_id)
614
615 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
616
617 create table config (
618
619     section varchar(32) comment 'configuration section',
620     setting varchar(32) comment 'configuration setting',
621     value varchar(255) comment 'configuration value',
622
623     constraint primary key (section, setting)
624
625 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
626
627 create table profile_role (
628
629     profile_id integer not null comment 'account having the role' references profile (id),
630     role    varchar(32) not null comment 'string representing the role',
631     created datetime not null comment 'date the role was granted',
632
633     constraint primary key (profile_id, role),
634     index profile_role_role_created_profile_id_idx (role, created, profile_id)
635
636 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
637
638 create table location_namespace (
639
640     id integer primary key comment 'identity for this namespace',
641     description varchar(255) comment 'description of the namespace',
642     created datetime not null comment 'date the record was created',
643     modified timestamp comment 'date this record was modified'
644
645 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
646
647 create table login_token (
648     user_id integer not null comment 'user owning this token' references user (id),
649     token char(32) not null comment 'token useable for logging in',
650     created datetime not null comment 'date this record was created',
651     modified timestamp comment 'date this record was modified',
652
653     constraint primary key (user_id)
654 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
655
656 create table user_location_prefs (
657     user_id integer not null comment 'user who has the preference' references user (id),
658     share_location tinyint default 1 comment 'Whether to share location data',
659     created datetime not null comment 'date this record was created',
660     modified timestamp comment 'date this record was modified',
661
662     constraint primary key (user_id)
663 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
664
665 create table inbox (
666
667     user_id integer not null comment 'user receiving the notice' references user (id),
668     notice_ids blob comment 'packed list of notice ids',
669
670     constraint primary key (user_id)
671
672 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
673
674 create table conversation (
675     id integer auto_increment primary key comment 'unique identifier',
676     uri varchar(225) unique comment 'URI of the conversation',
677     created datetime not null comment 'date this record was created',
678     modified timestamp comment 'date this record was modified'
679 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
680
681 create table local_group (
682
683    group_id integer primary key comment 'group represented' references user_group (id),
684    nickname varchar(64) unique key comment 'group represented',
685
686    created datetime not null comment 'date this record was created',
687    modified timestamp comment 'date this record was modified'
688
689 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
690