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