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