]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - db/laconica.sql
c87340e8e09a1e13e24356a5ce9efbf01726a7e7
[quix0rs-gnu-social.git] / db / laconica.sql
1 /* local and remote users have profiles */
2
3 create table profile (
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',
13
14     index profile_nickname_idx (nickname),
15     FULLTEXT(nickname, fullname, location, bio, homepage)
16 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
17
18 create table avatar (
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',
28
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;
32
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;
40
41 /* local users */
42
43 create table user (
44
45     id integer primary key comment 'foreign key to profile table' references profile (id),
46     nickname varchar(64) unique key comment 'nickname or username, duped in profile',
47     password varchar(255) comment 'salted password, can be null for OpenID users',
48     email varchar(255) unique key comment 'email address for password recovery etc.',
49     incomingemail varchar(255) unique key comment 'email address for post-by-email',
50     emailnotifysub tinyint default 1 comment 'Notify by email of subscriptions',
51     emailnotifyfav tinyint default 1 comment 'Notify by email of favorites',
52     emailnotifynudge tinyint default 1 comment 'Notify by email of nudges',
53     emailnotifymsg tinyint default 1 comment 'Notify by email of direct messages',
54     emailnotifyattn tinyint default 1 comment 'Notify by email of @-replies',
55     emailmicroid tinyint default 1 comment 'whether to publish email microid',
56     language varchar(50) comment 'preferred language',
57     timezone varchar(50) comment 'timezone',
58     emailpost tinyint default 1 comment 'Post by email',
59     jabber varchar(255) unique key comment 'jabber ID for notices',
60     jabbernotify tinyint default 0 comment 'whether to send notices to jabber',
61     jabberreplies tinyint default 0 comment 'whether to send notices to jabber on replies',
62     jabbermicroid tinyint default 1 comment 'whether to publish xmpp microid',
63     updatefrompresence tinyint default 0 comment 'whether to record updates from Jabber presence notices',
64     sms varchar(64) unique key comment 'sms phone number',
65     carrier integer comment 'foreign key to sms_carrier' references sms_carrier (id),
66     smsnotify tinyint default 0 comment 'whether to send notices to SMS',
67     smsreplies tinyint default 0 comment 'whether to send notices to SMS on replies',
68     smsemail varchar(255) comment 'built from sms and carrier',
69     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
70     autosubscribe tinyint default 0 comment 'automatically subscribe to users who subscribe to us',
71     urlshorteningservice varchar(50) default 'ur1.ca' comment 'service to use for auto-shortening URLs',
72     inboxed tinyint default 0 comment 'has an inbox been created for this user?',
73     created datetime not null comment 'date this record was created',
74     modified timestamp comment 'date this record was modified',
75     design_id integer comment 'id of a design' references design(id),
76     viewdesigns tinyint default 1 comment 'whether to view user-provided designs',
77
78     index user_smsemail_idx (smsemail)
79 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
80
81 /* remote people */
82
83 create table remote_profile (
84     id integer primary key comment 'foreign key to profile table' references profile (id),
85     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
86     postnoticeurl varchar(255) comment 'URL we use for posting notices',
87     updateprofileurl varchar(255) comment 'URL we use for updates to this profile',
88     created datetime not null comment 'date this record was created',
89     modified timestamp comment 'date this record was modified'
90 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
91
92 create table subscription (
93     subscriber integer not null comment 'profile listening',
94     subscribed integer not null comment 'profile being listened to',
95     jabber tinyint default 1 comment 'deliver jabber messages',
96     sms tinyint default 1 comment 'deliver sms messages',
97     token varchar(255) comment 'authorization token',
98     secret varchar(255) comment 'token secret',
99     created datetime not null comment 'date this record was created',
100     modified timestamp comment 'date this record was modified',
101
102     constraint primary key (subscriber, subscribed),
103     index subscription_subscriber_idx (subscriber),
104     index subscription_subscribed_idx (subscribed),
105     index subscription_token_idx (token)
106 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
107
108 create table notice (
109     id integer auto_increment primary key comment 'unique identifier',
110     profile_id integer not null comment 'who made the update' references profile (id),
111     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
112     content varchar(140) comment 'update content',
113     rendered text comment 'HTML version of the content',
114     url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)',
115     created datetime not null comment 'date this record was created',
116     modified timestamp comment 'date this record was modified',
117     reply_to integer comment 'notice replied to (usually a guess)' references notice (id),
118     is_local tinyint default 0 comment 'notice was generated by a user',
119     source varchar(32) comment 'source of comment, like "web", "im", or "clientname"',
120     conversation integer comment 'id of root notice in this conversation' references notice (id),
121
122     index notice_profile_id_idx (profile_id),
123     index notice_conversation_idx (conversation),
124     index notice_created_idx (created),
125     index notice_replyto_idx (reply_to),
126     FULLTEXT(content)
127 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
128
129 create table notice_source (
130      code varchar(32) primary key not null comment 'source code',
131      name varchar(255) not null comment 'name of the source',
132      url varchar(255) not null comment 'url to link to',
133      created datetime not null comment 'date this record was created',
134      modified timestamp comment 'date this record was modified'
135 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
136
137 create table reply (
138     notice_id integer not null comment 'notice that is the reply' references notice (id),
139     profile_id integer not null comment 'profile replied to' references profile (id),
140     modified timestamp not null comment 'date this record was modified',
141     replied_id integer comment 'notice replied to (not used, see notice.reply_to)',
142
143     constraint primary key (notice_id, profile_id),
144     index reply_notice_id_idx (notice_id),
145     index reply_profile_id_idx (profile_id),
146     index reply_replied_id_idx (replied_id)
147
148 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
149
150 create table fave (
151     notice_id integer not null comment 'notice that is the favorite' references notice (id),
152     user_id integer not null comment 'user who likes this notice' references user (id),
153     modified timestamp not null comment 'date this record was modified',
154
155     constraint primary key (notice_id, user_id),
156     index fave_notice_id_idx (notice_id),
157     index fave_user_id_idx (user_id),
158     index fave_modified_idx (modified)
159
160 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
161
162 /* tables for OAuth */
163
164 create table consumer (
165     consumer_key varchar(255) primary key comment 'unique identifier, root URL',
166     seed char(32) not null comment 'seed for new tokens by this consumer',
167
168     created datetime not null comment 'date this record was created',
169     modified timestamp comment 'date this record was modified'
170 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
171
172 create table token (
173     consumer_key varchar(255) not null comment 'unique identifier, root URL' references consumer (consumer_key),
174     tok char(32) not null comment 'identifying value',
175     secret char(32) not null comment 'secret value',
176     type tinyint not null default 0 comment 'request or access',
177     state tinyint default 0 comment 'for requests, 0 = initial, 1 = authorized, 2 = used',
178
179     created datetime not null comment 'date this record was created',
180     modified timestamp comment 'date this record was modified',
181
182     constraint primary key (consumer_key, tok)
183 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
184
185 create table nonce (
186     consumer_key varchar(255) not null comment 'unique identifier, root URL',
187     tok char(32) null comment 'buggy old value, ignored',
188     nonce char(32) not null comment 'nonce',
189     ts datetime not null comment 'timestamp sent',
190
191     created datetime not null comment 'date this record was created',
192     modified timestamp comment 'date this record was modified',
193
194     constraint primary key (consumer_key, ts, nonce)
195 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
196
197 /* One-to-many relationship of user to openid_url */
198
199 create table user_openid (
200     canonical varchar(255) primary key comment 'Canonical true URL',
201     display varchar(255) not null unique key comment 'URL for viewing, may be different from canonical',
202     user_id integer not null comment 'user owning this URL' references user (id),
203     created datetime not null comment 'date this record was created',
204     modified timestamp comment 'date this record was modified',
205
206     index user_openid_user_id_idx (user_id)
207 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
208
209 /* These are used by JanRain OpenID library */
210
211 create table oid_associations (
212     server_url BLOB,
213     handle VARCHAR(255) character set latin1,
214     secret BLOB,
215     issued INTEGER,
216     lifetime INTEGER,
217     assoc_type VARCHAR(64),
218     PRIMARY KEY (server_url(255), handle)
219 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
220
221 create table oid_nonces (
222     server_url VARCHAR(2047),
223     timestamp INTEGER,
224     salt CHAR(40),
225     UNIQUE (server_url(255), timestamp, salt)
226 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
227
228 create table confirm_address (
229     code varchar(32) not null primary key comment 'good random code',
230     user_id integer not null comment 'user who requested confirmation' references user (id),
231     address varchar(255) not null comment 'address (email, Jabber, SMS, etc.)',
232     address_extra varchar(255) not null comment 'carrier ID, for SMS',
233     address_type varchar(8) not null comment 'address type ("email", "jabber", "sms")',
234     claimed datetime comment 'date this was claimed for queueing',
235     sent datetime comment 'date this was sent for queueing',
236     modified timestamp comment 'date this record was modified'
237 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
238
239 create table remember_me (
240     code varchar(32) not null primary key comment 'good random code',
241     user_id integer not null comment 'user who is logged in' references user (id),
242     modified timestamp comment 'date this record was modified'
243 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
244
245 create table queue_item (
246
247     notice_id integer not null comment 'notice queued' references notice (id),
248     transport varchar(8) not null comment 'queue for what? "email", "jabber", "sms", "irc", ...',
249     created datetime not null comment 'date this record was created',
250     claimed datetime comment 'date this item was claimed',
251
252     constraint primary key (notice_id, transport),
253     index queue_item_created_idx (created)
254
255 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
256
257 /* Hash tags */
258 create table notice_tag (
259     tag varchar( 64 ) not null comment 'hash tag associated with this notice',
260     notice_id integer not null comment 'notice tagged' references notice (id),
261     created datetime not null comment 'date this record was created',
262
263     constraint primary key (tag, notice_id),
264     index notice_tag_created_idx (created),
265     index notice_tag_notice_id_idx (notice_id)
266 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
267
268 /* Synching with foreign services */
269
270 create table foreign_service (
271      id int not null primary key comment 'numeric key for service',
272      name varchar(32) not null unique key comment 'name of the service',
273      description varchar(255) comment 'description',
274      created datetime not null comment 'date this record was created',
275      modified timestamp comment 'date this record was modified'
276 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
277
278 create table foreign_user (
279      id int not null comment 'unique numeric key on foreign service',
280      service int not null comment 'foreign key to service' references foreign_service(id),
281      uri varchar(255) not null unique key comment 'identifying URI',
282      nickname varchar(255) comment 'nickname on foreign service',
283      created datetime not null comment 'date this record was created',
284      modified timestamp comment 'date this record was modified',
285
286      constraint primary key (id, service)
287 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
288
289 create table foreign_link (
290      user_id int comment 'link to user on this system, if exists' references user (id),
291      foreign_id int comment 'link ' references foreign_user(id),
292      service int not null comment 'foreign key to service' references foreign_service(id),
293      credentials varchar(255) comment 'authc credentials, typically a password',
294      noticesync tinyint not null default 1 comment 'notice synchronization, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies',
295      friendsync tinyint not null default 2 comment 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming',
296      profilesync tinyint not null default 1 comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming',
297      last_noticesync datetime default null comment 'last time notices were imported',
298      last_friendsync datetime default null comment 'last time friends were imported',
299      created datetime not null comment 'date this record was created',
300      modified timestamp comment 'date this record was modified',
301
302      constraint primary key (user_id, foreign_id, service),
303      index foreign_user_user_id_idx (user_id)
304 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
305
306 create table foreign_subscription (
307      service int not null comment 'service where relationship happens' references foreign_service(id),
308      subscriber int not null comment 'subscriber on foreign service' references foreign_user (id),
309      subscribed int not null comment 'subscribed user' references foreign_user (id),
310      created datetime not null comment 'date this record was created',
311
312      constraint primary key (service, subscriber, subscribed),
313      index foreign_subscription_subscriber_idx (subscriber),
314      index foreign_subscription_subscribed_idx (subscribed)
315 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
316
317 create table invitation (
318      code varchar(32) not null primary key comment 'random code for an invitation',
319      user_id int not null comment 'who sent the invitation' references user (id),
320      address varchar(255) not null comment 'invitation sent to',
321      address_type varchar(8) not null comment 'address type ("email", "jabber", "sms")',
322      created datetime not null comment 'date this record was created',
323
324      index invitation_address_idx (address, address_type),
325      index invitation_user_id_idx (user_id)
326 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
327
328 create table message (
329     id integer auto_increment primary key comment 'unique identifier',
330     uri varchar(255) unique key comment 'universally unique identifier',
331     from_profile integer not null comment 'who the message is from' references profile (id),
332     to_profile integer not null comment 'who the message is to' references profile (id),
333     content varchar(140) comment 'message content',
334     rendered text comment 'HTML version of the content',
335     url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)',
336     created datetime not null comment 'date this record was created',
337     modified timestamp comment 'date this record was modified',
338     source varchar(32) comment 'source of comment, like "web", "im", or "clientname"',
339
340     index message_from_idx (from_profile),
341     index message_to_idx (to_profile),
342     index message_created_idx (created)
343 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
344
345 create table notice_inbox (
346     user_id integer not null comment 'user receiving the message' references user (id),
347     notice_id integer not null comment 'notice received' references notice (id),
348     created datetime not null comment 'date the notice was created',
349     source tinyint default 1 comment 'reason it is in the inbox, 1=subscription',
350
351     constraint primary key (user_id, notice_id),
352     index notice_inbox_notice_id_idx (notice_id)
353 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
354
355 create table profile_tag (
356    tagger integer not null comment 'user making the tag' references user (id),
357    tagged integer not null comment 'profile tagged' references profile (id),
358    tag varchar(64) not null comment 'hash tag associated with this notice',
359    modified timestamp comment 'date the tag was added',
360
361    constraint primary key (tagger, tagged, tag),
362    index profile_tag_modified_idx (modified),
363    index profile_tag_tagger_tag_idx (tagger, tag),
364    index profile_tag_tagged_idx (tagged)
365 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
366
367 create table profile_block (
368    blocker integer not null comment 'user making the block' references user (id),
369    blocked integer not null comment 'profile that is blocked' references profile (id),
370    modified timestamp comment 'date of blocking',
371
372    constraint primary key (blocker, blocked)
373
374 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
375
376 create table user_group (
377     id integer auto_increment primary key comment 'unique identifier',
378
379     nickname varchar(64) unique key comment 'nickname for addressing',
380     fullname varchar(255) comment 'display name',
381     homepage varchar(255) comment 'URL, cached so we dont regenerate',
382     description varchar(140) comment 'descriptive biography',
383     location varchar(255) comment 'related physical location, if any',
384
385     original_logo varchar(255) comment 'original size logo',
386     homepage_logo varchar(255) comment 'homepage (profile) size logo',
387     stream_logo varchar(255) comment 'stream-sized logo',
388     mini_logo varchar(255) comment 'mini logo',
389
390     created datetime not null comment 'date this record was created',
391     modified timestamp comment 'date this record was modified',
392
393     index user_group_nickname_idx (nickname)
394
395 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
396
397 create table group_member (
398     group_id integer not null comment 'foreign key to user_group' references user_group (id),
399     profile_id integer not null comment 'foreign key to profile table' references profile (id),
400     is_admin boolean default false comment 'is this user an admin?',
401
402     created datetime not null comment 'date this record was created',
403     modified timestamp comment 'date this record was modified',
404
405     constraint primary key (group_id, profile_id),
406     index group_member_profile_id_idx (profile_id),
407     index group_member_created_idx (created)
408
409 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
410
411 create table related_group (
412     group_id integer not null comment 'foreign key to user_group' references user_group (id),
413     related_group_id integer not null comment 'foreign key to user_group' references user_group (id),
414
415     created datetime not null comment 'date this record was created',
416
417     constraint primary key (group_id, related_group_id)
418
419 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
420
421 create table group_inbox (
422     group_id integer not null comment 'group receiving the message' references user_group (id),
423     notice_id integer not null comment 'notice received' references notice (id),
424     created datetime not null comment 'date the notice was created',
425
426     constraint primary key (group_id, notice_id),
427     index group_inbox_created_idx (created)
428
429 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
430
431 create table file (
432     id integer primary key auto_increment,
433     url varchar(255), mimetype varchar(50),
434     size integer,
435     title varchar(255),
436     date integer(11),
437     protected integer(1),
438
439     unique(url)
440 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
441
442 create table file_oembed (
443     id integer primary key auto_increment,
444     file_id integer,
445     version varchar(20),
446     type varchar(20),
447     provider varchar(50),
448     provider_url varchar(255),
449     width integer,
450     height integer,
451     html text,
452     title varchar(255),
453     author_name varchar(50),
454     author_url varchar(255),
455     url varchar(255),
456
457     unique(file_id)
458 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
459
460 create table file_redirection (
461     id integer primary key auto_increment,
462     url varchar(255),
463     file_id integer,
464     redirections integer,
465     httpcode integer,
466
467     unique(url)
468 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
469
470 create table file_thumbnail (
471     id integer primary key auto_increment,
472     file_id integer,
473     url varchar(255),
474     width integer,
475     height integer,
476
477     unique(file_id),
478     unique(url)
479 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
480
481 create table file_to_post (
482     id integer primary key auto_increment,
483     file_id integer,
484     post_id integer,
485
486     unique(file_id, post_id)
487 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
488
489 create table design (
490     id integer primary key auto_increment comment 'design ID',
491     backgroundcolor integer comment 'main background color',
492     contentcolor integer comment 'content area background color',
493     sidebarcolor integer comment 'sidebar background color',
494     textcolor integer comment 'text color',
495     linkcolor integer comment 'link color',
496     backgroundimage varchar(255) comment 'background image, if any'
497 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;