]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - db/laconica.sql
87ac6e26db686f98194c0d8267a1be03157acebc
[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_bin;
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 auto_increment 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     id integer primary key comment 'foreign key to profile table' references profile (id),
45     nickname varchar(64) unique key comment 'nickname or username, duped in profile',
46     password varchar(255) comment 'salted password, can be null for OpenID users',
47     email varchar(255) unique key comment 'email address for password recovery etc.',
48     incomingemail varchar(255) unique key comment 'email address for post-by-email',
49     emailnotifysub tinyint default 1 comment 'Notify by email of subscriptions',
50     emailnotifyfav tinyint default 1 comment 'Notify by email of favorites',
51     emailnotifymsg tinyint default 1 comment 'Notify by email of direct messages',
52     emailmicroid tinyint default 1 comment 'whether to publish email microid',
53     language varchar(50) comment 'preferred language',
54     timezone varchar(50) comment 'timezone',
55     emailpost tinyint default 1 comment 'Post by email',
56     jabber varchar(255) unique key comment 'jabber ID for notices',
57     jabbernotify tinyint default 0 comment 'whether to send notices to jabber',
58     jabberreplies tinyint default 0 comment 'whether to send notices to jabber on replies',
59     jabbermicroid tinyint default 1 comment 'whether to publish xmpp microid',
60     updatefrompresence tinyint default 0 comment 'whether to record updates from Jabber presence notices',
61     sms varchar(64) unique key comment 'sms phone number',
62     carrier integer comment 'foreign key to sms_carrier' references sms_carrier (id),
63     smsnotify tinyint default 0 comment 'whether to send notices to SMS',
64     smsreplies tinyint default 0 comment 'whether to send notices to SMS on replies',
65     smsemail varchar(255) comment 'built from sms and carrier',
66     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
67     autosubscribe tinyint default 0 comment 'automatically subscribe to users who subscribe to us',
68     urlshorteningservice varchar(50) default 'ur1.ca' comment 'service to use for auto-shortening URLs',
69     inboxed tinyint default 0 comment 'has an inbox been created for this user?',
70     created datetime not null comment 'date this record was created',
71     modified timestamp comment 'date this record was modified',
72
73     index user_smsemail_idx (smsemail)
74 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
75
76 /* remote people */
77
78 create table remote_profile (
79     id integer primary key comment 'foreign key to profile table' references profile (id),
80     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
81     postnoticeurl varchar(255) comment 'URL we use for posting notices',
82     updateprofileurl varchar(255) comment 'URL we use for updates to this profile',
83     created datetime not null comment 'date this record was created',
84     modified timestamp comment 'date this record was modified'
85 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
86
87 create table subscription (
88     subscriber integer not null comment 'profile listening',
89     subscribed integer not null comment 'profile being listened to',
90     token varchar(255) comment 'authorization token',
91     secret varchar(255) comment 'token secret',
92     created datetime not null comment 'date this record was created',
93     modified timestamp comment 'date this record was modified',
94
95     constraint primary key (subscriber, subscribed),
96     index subscription_subscriber_idx (subscriber),
97     index subscription_subscribed_idx (subscribed),
98     index subscription_token_idx (token)
99 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
100
101 create table notice (
102
103     id integer auto_increment primary key comment 'unique identifier',
104     profile_id integer not null comment 'who made the update' references profile (id),
105     uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
106     content varchar(140) comment 'update content',
107     rendered text comment 'HTML version of the content',
108     url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)',
109     created datetime not null comment 'date this record was created',
110     modified timestamp comment 'date this record was modified',
111     reply_to integer comment 'notice replied to (usually a guess)' references notice (id),
112     is_local tinyint default 0 comment 'notice was generated by a user',
113     source varchar(32) comment 'source of comment, like "web", "im", or "clientname"',
114
115     index notice_profile_id_idx (profile_id),
116     index notice_created_idx (created),
117     FULLTEXT(content)
118 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin;
119
120 create table notice_source (
121      code varchar(32) primary key not null comment 'source code',
122      name varchar(255) not null comment 'name of the source',
123      url varchar(255) not null comment 'url to link to',
124      created datetime not null comment 'date this record was created',
125      modified timestamp comment 'date this record was modified'
126 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
127
128 create table reply (
129
130     notice_id integer not null comment 'notice that is the reply' references notice (id),
131     profile_id integer not null comment 'profile replied to' references profile (id),
132     modified timestamp not null comment 'date this record was modified',
133     replied_id integer comment 'notice replied to (not used, see notice.reply_to)',
134
135     constraint primary key (notice_id, profile_id),
136     index reply_notice_id_idx (notice_id),
137     index reply_profile_id_idx (profile_id),
138     index reply_replied_id_idx (replied_id)
139
140 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
141
142 create table fave (
143
144     notice_id integer not null comment 'notice that is the favorite' references notice (id),
145     user_id integer not null comment 'user who likes this notice' references user (id),
146     modified timestamp not null comment 'date this record was modified',
147
148     constraint primary key (notice_id, user_id),
149     index fave_notice_id_idx (notice_id),
150     index fave_user_id_idx (user_id),
151     index fave_modified_idx (modified)
152
153 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
154
155 /* tables for OAuth */
156
157 create table consumer (
158     consumer_key varchar(255) primary key comment 'unique identifier, root URL',
159     seed char(32) not null comment 'seed for new tokens by this consumer',
160
161     created datetime not null comment 'date this record was created',
162     modified timestamp comment 'date this record was modified'
163 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
164
165 create table token (
166     consumer_key varchar(255) not null comment 'unique identifier, root URL' references consumer (consumer_key),
167     tok char(32) not null comment 'identifying value',
168     secret char(32) not null comment 'secret value',
169     type tinyint not null default 0 comment 'request or access',
170     state tinyint default 0 comment 'for requests; 0 = initial, 1 = authorized, 2 = used',
171
172     created datetime not null comment 'date this record was created',
173     modified timestamp comment 'date this record was modified',
174
175     constraint primary key (consumer_key, tok)
176 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
177
178 create table nonce (
179     consumer_key varchar(255) not null comment 'unique identifier, root URL',
180     tok char(32) not null comment 'identifying value',
181     nonce char(32) not null comment 'nonce',
182     ts datetime not null comment 'timestamp sent',
183
184     created datetime not null comment 'date this record was created',
185     modified timestamp comment 'date this record was modified',
186
187     constraint primary key (consumer_key, tok, nonce),
188     constraint foreign key (consumer_key, tok) references token (consumer_key, tok)
189 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
190
191 /* One-to-many relationship of user to openid_url */
192
193 create table user_openid (
194     canonical varchar(255) primary key comment 'Canonical true URL',
195     display varchar(255) not null unique key comment 'URL for viewing, may be different from canonical',
196     user_id integer not null comment 'user owning this URL' references user (id),
197     created datetime not null comment 'date this record was created',
198     modified timestamp comment 'date this record was modified',
199
200     index user_openid_user_id_idx (user_id)
201 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
202
203 /* These are used by JanRain OpenID library */
204
205 create table oid_associations (
206     server_url BLOB,
207     handle VARCHAR(255) character set latin1,
208     secret BLOB,
209     issued INTEGER,
210     lifetime INTEGER,
211     assoc_type VARCHAR(64),
212     PRIMARY KEY (server_url(255), handle)
213 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
214
215 create table oid_nonces (
216     server_url VARCHAR(2047),
217     timestamp INTEGER,
218     salt CHAR(40),
219     UNIQUE (server_url(255), timestamp, salt)
220 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
221
222 create table confirm_address (
223     code varchar(32) not null primary key comment 'good random code',
224     user_id integer not null comment 'user who requested confirmation' references user (id),
225     address varchar(255) not null comment 'address (email, Jabber, SMS, etc.)',
226     address_extra varchar(255) not null comment 'carrier ID, for SMS',
227     address_type varchar(8) not null comment 'address type ("email", "jabber", "sms")',
228     claimed datetime comment 'date this was claimed for queueing',
229     sent datetime comment 'date this was sent for queueing',
230     modified timestamp comment 'date this record was modified'
231 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
232
233 create table remember_me (
234     code varchar(32) not null primary key comment 'good random code',
235     user_id integer not null comment 'user who is logged in' references user (id),
236     modified timestamp comment 'date this record was modified'
237 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
238
239 create table queue_item (
240
241     notice_id integer not null comment 'notice queued' references notice (id),
242     transport varchar(8) not null comment 'queue for what? "email", "jabber", "sms", "irc", ...',
243     created datetime not null comment 'date this record was created',
244     claimed datetime comment 'date this item was claimed',
245
246     constraint primary key (notice_id, transport),
247     index queue_item_created_idx (created)
248
249 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
250
251 /* Hash tags */
252 create table notice_tag (
253     tag varchar( 64 ) not null comment 'hash tag associated with this notice',
254     notice_id integer not null comment 'notice tagged' references notice (id),
255     created datetime not null comment 'date this record was created',
256
257     constraint primary key (tag, notice_id),
258     index notice_tag_created_idx (created)
259 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
260
261 /* Synching with foreign services */
262
263 create table foreign_service (
264      id int not null primary key comment 'numeric key for service',
265      name varchar(32) not null unique key comment 'name of the service',
266      description varchar(255) comment 'description',
267      created datetime not null comment 'date this record was created',
268      modified timestamp comment 'date this record was modified'
269 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
270
271 create table foreign_user (
272      id int not null comment 'unique numeric key on foreign service',
273      service int not null comment 'foreign key to service' references foreign_service(id),
274      uri varchar(255) not null unique key comment 'identifying URI',
275      nickname varchar(255) comment 'nickname on foreign service',
276      created datetime not null comment 'date this record was created',
277      modified timestamp comment 'date this record was modified',
278
279      constraint primary key (id, service)
280 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
281
282 create table foreign_link (
283      user_id int comment 'link to user on this system, if exists' references user (id),
284      foreign_id int comment 'link ' references foreign_user(id),
285      service int not null comment 'foreign key to service' references foreign_service(id),
286      credentials varchar(255) comment 'authc credentials, typically a password',
287      noticesync tinyint not null default 1 comment 'notice synchronization, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies',
288      friendsync tinyint not null default 2 comment 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming',
289      profilesync tinyint not null default 1 comment 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming',
290      created datetime not null comment 'date this record was created',
291      modified timestamp comment 'date this record was modified',
292
293      constraint primary key (user_id, foreign_id, service),
294      index foreign_user_user_id_idx (user_id)
295 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
296
297 create table foreign_subscription (
298      service int not null comment 'service where relationship happens' references foreign_service(id),
299      subscriber int not null comment 'subscriber on foreign service' references foreign_user (id),
300      subscribed int not null comment 'subscribed user' references foreign_user (id),
301      created datetime not null comment 'date this record was created',
302
303      constraint primary key (service, subscriber, subscribed),
304      index foreign_subscription_subscriber_idx (subscriber),
305      index foreign_subscription_subscribed_idx (subscribed)
306 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
307
308 create table invitation (
309      code varchar(32) not null primary key comment 'random code for an invitation',
310      user_id int not null comment 'who sent the invitation' references user (id),
311      address varchar(255) not null comment 'invitation sent to',
312      address_type varchar(8) not null comment 'address type ("email", "jabber", "sms")',
313      created datetime not null comment 'date this record was created',
314
315      index invitation_address_idx (address, address_type),
316      index invitation_user_id_idx (user_id)
317 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
318
319 create table message (
320
321     id integer auto_increment primary key comment 'unique identifier',
322     uri varchar(255) unique key comment 'universally unique identifier',
323     from_profile integer not null comment 'who the message is from' references profile (id),
324     to_profile integer not null comment 'who the message is to' references profile (id),
325     content varchar(140) comment 'message content',
326     rendered text comment 'HTML version of the content',
327     url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)',
328     created datetime not null comment 'date this record was created',
329     modified timestamp comment 'date this record was modified',
330     source varchar(32) comment 'source of comment, like "web", "im", or "clientname"',
331     
332     index message_from_idx (from_profile),
333     index message_to_idx (to_profile),
334     index message_created_idx (created)
335 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
336
337 create table notice_inbox (
338
339     user_id integer not null comment 'user receiving the message' references user (id),
340     notice_id integer not null comment 'notice received' references notice (id),
341     created datetime not null comment 'date the notice was created',
342     source tinyint default 1 comment 'reason it is in the inbox; 1=subscription',
343     
344     constraint primary key (user_id, notice_id),
345     index notice_inbox_notice_id_idx (notice_id)
346 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;