]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - db/core.php
output tweak hack for primary keys on single line
[quix0rs-gnu-social.git] / db / core.php
1 <?php
2
3 /**
4
5 Some notes...
6
7 drupal docs don't list a bool type, but it might be nice to use rather than 'tinyint'
8 note however that we use bitfields and things as well in tinyints
9
10 decimal <-> numeric
11
12 timestamps... how to specify?
13 fulltext indexes?
14 got one or two things wanting a custom charset setting on a field?
15
16 foreign keys are kinda funky...
17     those specified in inline syntax (as all in the original .sql) are NEVER ENFORCED on mysql
18     those made with an explicit 'foreign key' WITHIN INNODB and IF there's a proper index, do get enforced
19     double-check what we've been doing on postgres?
20
21 */
22
23 $schema['profile'] = array(
24     'description' => 'local and remote users have profiles',
25     'fields' => array(
26         'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
27         'nickname' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'nickname or username'),
28         'fullname' => array('type' => 'varchar', 'length' => 255, 'description' => 'display name'),
29         'profileurl' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL, cached so we dont regenerate'),
30         'homepage' => array('type' => 'varchar', 'length' => 255, 'description' => 'identifying URL'),
31         'bio' => array('type' => 'text', 'description' => 'descriptive biography'),
32         'location' => array('type' => 'varchar', 'length' => 255, 'description' => 'physical location'),
33         'lat' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'),
34         'lon' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'),
35         'location_id' => array('type' => 'int', 'description' => 'location id if possible'),
36         'location_ns' => array('type' => 'int', 'description' => 'namespace for location'),
37
38         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
39         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
40     ),
41     'primary key' => array('id'),
42     'indexes' => array(
43         'profile_nickname_idx' => array('nickname'),
44     ),
45     'fulltext indexes' => array(
46         'content' => array('nickname', 'fullname', 'location', 'bio', 'homepage') // ??
47     ),
48 );
49
50 $schema['avatar'] = array(
51     'fields' => array(
52         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
53         'original' => array('type' => 'boolean', 'default' => false, 'description' => 'uploaded by user or generated?'),
54         'width' => array('type' => 'int', 'not null' => true, 'description' => 'image width'),
55         'height' => array('type' => 'int', 'not null' => true, 'description' => 'image height'),
56         'mediatype' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'file type'),
57         'filename' => array('type' => 'varchar', 'length' => 255, 'description' => 'local filename, if local'),
58         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'avatar location'),
59         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
60         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
61     ),
62     'primary key' => array('profile_id', 'width', 'height'),
63     'unique keys' => array(
64         'avatar_url_idx' => array('url'),
65     ),
66     'foreign keys' => array(
67         'profile_id' => array('profile' => 'id'),
68     ),
69     'indexes' => array(
70         'avatar_profile_id_idx' => array('profile_id'),
71     ),
72 );
73
74 $schema['sms_carrier'] = array(
75     'fields' => array(
76         'id' => array('type' => 'int', 'description' => 'primary key for SMS carrier'),
77         'name' => array('type' => 'varchar', 'length' => 64, 'description' => 'name of the carrier'),
78         'email_pattern' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'sprintf pattern for making an email address from a phone number'),
79         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
80         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
81     ),
82     'primary key' => array('id'),
83     'unique keys' => array(
84         'sms_carrier_name_idx' => array('name'),
85     ),
86 );
87
88 $schema['user'] = array(
89     'description' => 'local users',
90     'fields' => array(
91         'id' => array('type' => 'int', 'description' => 'foreign key to profile table'),
92         'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'nickname or username, duped in profile'),
93         'password' => array('type' => 'varchar', 'length' => 255, 'description' => 'salted password, can be null for OpenID users'),
94         'email' => array('type' => 'varchar', 'length' => 255, 'description' => 'email address for password recovery etc.'),
95         'incomingemail' => array('type' => 'varchar', 'length' => 255, 'description' => 'email address for post-by-email'),
96         'emailnotifysub' => array('type' => 'bool', 'default' => 1, 'description' => 'Notify by email of subscriptions'),
97         'emailnotifyfav' => array('type' => 'bool', 'default' => 1, 'description' => 'Notify by email of favorites'),
98         'emailnotifynudge' => array('type' => 'bool', 'default' => 1, 'description' => 'Notify by email of nudges'),
99         'emailnotifymsg' => array('type' => 'bool', 'default' => 1, 'description' => 'Notify by email of direct messages'),
100         'emailnotifyattn' => array('type' => 'bool', 'default' => 1, 'description' => 'Notify by email of @-replies'),
101         'emailmicroid' => array('type' => 'bool', 'default' => 1, 'description' => 'whether to publish email microid'),
102         'language' => array('type' => 'varchar', 'length' => 50, 'description' => 'preferred language'),
103         'timezone' => array('type' => 'varchar', 'length' => 50, 'description' => 'timezone'),
104         'emailpost' => array('type' => 'bool', 'default' => 1, 'description' => 'Post by email'),
105         'sms' => array('type' => 'varchar', 'length' => 64, 'description' => 'sms phone number'),
106         'carrier' => array('type' => 'int', 'description' => 'foreign key to sms_carrier'),
107         'smsnotify' => array('type' => 'bool', 'default' => 0, 'description' => 'whether to send notices to SMS'),
108         'smsreplies' => array('type' => 'bool', 'default' => 0, 'description' => 'whether to send notices to SMS on replies'),
109         'smsemail' => array('type' => 'varchar', 'length' => 255, 'description' => 'built from sms and carrier'),
110         'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier, usually a tag URI'),
111         'autosubscribe' => array('type' => 'bool', 'default' => 0, 'description' => 'automatically subscribe to users who subscribe to us'),
112         'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'ur1.ca', 'description' => 'service to use for auto-shortening URLs'),
113         'inboxed' => array('type' => 'bool', 'default' => 0, 'description' => 'has an inbox been created for this user?'),
114         'design_id' => array('type' => 'int', 'description' => 'id of a design'),
115         'viewdesigns' => array('type' => 'bool', 'default' => 1, 'description' => 'whether to view user-provided designs'),
116
117         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
118         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
119     ),
120     'primary key' => array('id'),
121     'unique keys' => array(
122         'user_name_idx' => array('name'),
123         'user_email_idx' => array('email'),
124         'user_incomingemail_idx' => array('incomingemail'),
125         'user_sms_idx' => array('sms'),
126         'user_uri_idx' => array('uri'),
127     ),
128     'foreign keys' => array(
129         'id' => array('profile' => 'id'),
130         'carrier' => array('sms_carrier' => 'id'),
131         'design_id' => array('desgin' => 'id'),
132     ),
133     'indexes' => array(
134         'user_smsemail_idx' => array('smsemail'),
135     ),
136 );
137
138 $schema['remote_profile'] = array(
139     'description' => 'remote people (OMB)',
140     'fields' => array(
141         'id' => array('type' => 'int', 'description' => 'foreign key to profile table'),
142         'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier, usually a tag URI'),
143         'postnoticeurl' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL we use for posting notices'),
144         'updateprofileurl' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL we use for updates to this profile'),
145         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
146         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
147     ),
148     'primary key' => array('id'),
149     'unique keys' => array(
150         'remote_profile_uri_idx' => array('uri'),
151     ),
152     'foreign keys' => array(
153         'id' => array('profile' => 'id'),
154     ),
155 );
156
157 $schema['subscription'] = array(
158     'fields' => array(
159         'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'profile listening'),
160         'subscribed' => array('type' => 'int', 'not null' => true, 'description' => 'profile being listened to'),
161         'jabber' => array('type' => 'bool', 'default' => 1, 'description' => 'deliver jabber messages'),
162         'sms' => array('type' => 'bool', 'default' => 1, 'description' => 'deliver sms messages'),
163         'token' => array('type' => 'varchar', 'length' => 255, 'description' => 'authorization token'),
164         'secret' => array('type' => 'varchar', 'length' => 255, 'description' => 'token secret'),
165         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
166         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
167     ),
168     'primary key' => array('subscriber', 'subscribed'),
169     'indexes' => array(
170         'subscription_subscriber_idx' => array('subscriber', 'created'),
171         'subscription_subscribed_idx' => array('subscribed', 'created'),
172         'subscription_token_idx' => array('token'),
173     ),
174 );
175
176 $schema['notice'] = array(
177     'fields' => array(
178         'id' => array('type' => 'serial', 'description' => 'unique identifier'),
179         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'who made the update'),
180         'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier, usually a tag URI'),
181         'content' => array('type' => 'text', 'description' => 'update content'),
182         'rendered' => array('type' => 'text', 'description' => 'HTML version of the content'),
183         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of any attachment (image, video, bookmark, whatever)'),
184         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
185         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
186         'reply_to' => array('type' => 'int', 'description' => 'notice replied to (usually a guess)'),
187         'is_local' => array('type' => 'bool', 'default' => 0, 'description' => 'notice was generated by a user'),
188         'source' => array('type' => 'varchar', 'length' => 32, 'description' => 'source of comment, like "web", "im", or "clientname"'),
189         'conversation' => array('type' => 'int', 'description' => 'id of root notice in this conversation'),
190         'lat' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'),
191         'lon' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'),
192         'location_id' => array('type' => 'int', 'description' => 'location id if possible'),
193         'location_ns' => array('type' => 'int', 'description' => 'namespace for location'),
194         'repeat_of' => array('type' => 'int', 'description' => 'notice this is a repeat of'),
195     ),
196     'primary key' => array('id'),
197     'unique keys' => array(
198         'notice_uri_idx' => array('uri'),
199     ),
200     'foreign keys' => array(
201         'profile_id' => array('profile' => 'id'),
202         'reply_to' => array('notice', 'id'),
203         'conversation' => array('conversation', 'id'), # note... used to refer to notice.id
204         'repeat_of' => array('notice', 'id'), # @fixme: what about repeats of deleted notices?
205     ),
206     'indexes' => array(
207         'notice_profile_id_idx' => array('profile_id,created,id'),
208         'notice_conversation_idx' => array('conversation'),
209         'notice_created_idx' => array('created'),
210         'notice_replyto_idx' => array('reply_to'),
211         'notice_repeatof_idx' => array('repeat_of'),
212         'FULLTEXT' => array('content'),
213     ),
214 );
215
216 $schema['notice_source'] = array(
217     'fields' => array(
218         'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'source code'),
219         'name' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'name of the source'),
220         'url' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'url to link to'),
221         'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'date this record was created'),
222         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
223     ),
224     'primary key' => array('code'),
225 );
226
227 $schema['reply'] = array(
228     'fields' => array(
229         'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice that is the reply'),
230         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile replied to'),
231         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
232         'replied_id' => array('type' => 'int', 'description' => 'notice replied to (not used, see notice.reply_to)'),
233     ),
234     'primary key' => array('notice_id', 'profile_id'),
235     'foreign keys' => array(
236         'notice_id' => array('notice' => 'id'),
237         'profile_id' => array('profile' => 'id'),
238     ),
239     'indexes' => array(
240         'reply_notice_id_idx' => array('notice_id'),
241         'reply_profile_id_idx' => array('profile_id'),
242         'reply_replied_id_idx' => array('replied_id'),
243     ),
244 );
245
246 $schema['fave'] = array(
247     'fields' => array(
248         'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice that is the favorite'),
249         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who likes this notice'),
250         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
251     ),
252     'primary key' => array('notice_id', 'user_id'),
253     'foreign keys' => array(
254         'notice_id' => array('notice', 'id'),
255         'user_id' => array('profile', 'id'), // note: formerly referenced notice.id, but we can now record remote users' favorites
256     ),
257     'indexes' => array(
258         'fave_notice_id_idx' => array('notice_id'),
259         'fave_user_id_idx' => array('user_id', 'modified'),
260         'fave_modified_idx' => array('modified'),
261     ),
262 );
263
264 /* tables for OAuth */
265
266 $schema['consumer'] = array(
267     'description' => 'OAuth consumer record',
268     'fields' => array(
269         'consumer_key' => array('type' => 'varchar', 'length' => 255, 'description' => 'unique identifier, root URL'),
270         'consumer_secret' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'secret value'),
271         'seed' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'seed for new tokens by this consumer'),
272
273         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
274         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
275     ),
276     'primary key' => array('consumer_key'),
277 );
278
279 $schema['token'] = array(
280     'description' => 'OAuth token record',
281     'fields' => array(
282         'consumer_key' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'unique identifier, root URL'),
283         'tok' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'identifying value'),
284         'secret' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'secret value'),
285         'type' => array('type' => 'bool', 'not null' => true, 'default' => 0, 'description' => 'request or access'),
286         'state' => array('type' => 'bool', 'default' => 0, 'description' => 'for requests, 0 = initial, 1 = authorized, 2 = used'),
287         'verifier' => array('type' => 'varchar', 'length' => 255, 'description' => 'verifier string for OAuth 1.0a'),
288         'verified_callback' => array('type' => 'varchar', 'length' => 255, 'description' => 'verified callback URL for OAuth 1.0a'),
289
290         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
291         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
292     ),
293     'primary key' => array('consumer_key', 'tok'),
294     'foreign keys' => array(
295         'consumer_key' => array('consumer' => 'consumer_key'),
296     ),
297 );
298
299 $schema['nonce'] = array(
300     'description' => 'OAuth nonce record',
301     'fields' => array(
302         'consumer_key' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'unique identifier, root URL'),
303         'tok' => array('type' => 'char', 'length' => 32, 'description' => 'buggy old value, ignored'),
304         'nonce' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'nonce'),
305         'ts' => array('type' => 'datetime', 'not null' => true, 'description' => 'timestamp sent'),
306
307         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
308         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
309     ),
310     'primary key' => array('consumer_key', 'ts', 'nonce'),
311 );
312
313 $schema['oauth_application'] = array(
314     'description' => 'OAuth application registration record',
315     'fields' => array(
316         'id' => array('type' => 'serial', 'description' => 'unique identifier'),
317         'owner' => array('type' => 'int', 'not null' => true, 'description' => 'owner of the application'),
318         'consumer_key' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'application consumer key'),
319         'name' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'name of the application'),
320         'description' => array('type' => 'varchar', 'length' => 255, 'description' => 'description of the application'),
321         'icon' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'application icon'),
322         'source_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'application homepage - used for source link'),
323         'organization' => array('type' => 'varchar', 'length' => 255, 'description' => 'name of the organization running the application'),
324         'homepage' => array('type' => 'varchar', 'length' => 255, 'description' => 'homepage for the organization'),
325         'callback_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'url to redirect to after authentication'),
326         'type' => array('type' => 'bool', 'default' => 0, 'description' => 'type of app, 1 = browser, 2 = desktop'),
327         'access_type' => array('type' => 'bool', 'default' => 0, 'description' => 'default access type, bit 1 = read, bit 2 = write'),
328         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
329         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
330     ),
331     'primary key' => array('id'),
332     'unique keys' => array(
333         'oauth_application_name_idx' => array('name'), // in the long run, we should perhaps not force these unique, and use another source id
334     ),
335     'foreign keys' => array(
336         'owner' => array('profile' => 'id'), // Are remote users allowed to create oauth application records?
337         'consumer_key' => array('consumer' => 'consumer_key'),
338     ),
339 );
340
341 $schema['oauth_application_user'] = array(
342     'fields' => array(
343         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'user of the application'),
344         'application_id' => array('type' => 'int', 'not null' => true, 'description' => 'id of the application'),
345         'access_type' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'access type, bit 1 = read, bit 2 = write'),
346         'token' => array('type' => 'varchar', 'length' => 255, 'description' => 'request or access token'),
347         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
348         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
349     ),
350     'primary key' => array('profile_id', 'application_id'),
351     'foreign keys' => array(
352         'profile_id' => array('profile' => 'id'),
353         'application_id' => array('oauth_application' => 'id'),
354     ),
355 );
356
357 /* These are used by JanRain OpenID library */
358
359 $schema['oid_associations'] = array(
360     'fields' => array(
361         'server_url' => array('type' => 'blob'),
362         'handle' => array('type' => 'varchar', 'length' => 255), // character set latin1,
363         'secret' => array('type' => 'blob'),
364         'issued' => array('type' => 'int'),
365         'lifetime' => array('type' => 'int'),
366         'assoc_type' => array('type' => 'varchar', 'length' => 64),
367     ),
368     'primary key' => array(array('server_url', 255), 'handle'),
369 );
370
371 $schema['oid_nonces'] = array(
372     'fields' => array(
373         'server_url' => array('type' => 'varchar', 'length' => 2047),
374         'timestamp' => array('type' => 'int'),
375         'salt' => array('type' => 'char', 'length' => 40),
376     ),
377     'unique keys' => array(
378         'oid_nonces_server_url_type_idx' => array(array('server_url', 255), 'timestamp', 'salt'),
379     ),
380 );
381
382 $schema['confirm_address'] = array(
383     'fields' => array(
384         'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'good random code'),
385         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who requested confirmation'),
386         'address' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'address (email, xmpp, SMS, etc.)'),
387         'address_extra' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'carrier ID, for SMS'),
388         'address_type' => array('type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'),
389         'claimed' => array('type' => 'datetime', 'description' => 'date this was claimed for queueing'),
390         'sent' => array('type' => 'datetime', 'description' => 'date this was sent for queueing'),
391         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
392     ),
393     'primary key' => array('code'),
394     'foreign keys' => array(
395         'user_id' => array('user' => 'id'),
396     ),
397 );
398
399 $schema['remember_me'] = array(
400     'fields' => array(
401         'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'good random code'),
402         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who is logged in'),
403         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
404     ),
405     'primary key' => array('code'),
406     'foreign keys' => array(
407         'user_id' => array('user' => 'id'),
408     ),
409 );
410
411 $schema['queue_item'] = array(
412     'fields' => array(
413         'id' => array('type' => 'serial', 'description' => 'unique identifier'),
414         'frame' => array('type' => 'blob', 'not null' => true, 'description' => 'data: object reference or opaque string'),
415         'transport' => array('type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'queue for what? "email", "xmpp", "sms", "irc", ...'), // @fixme 8 chars is too short; bump up.
416         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
417         'claimed' => array('type' => 'datetime', 'description' => 'date this item was claimed'),
418     ),
419     'primary key' => array('id'),
420     'indexes' => array(
421         'queue_item_created_idx' => array('created'),
422     ),
423 );
424
425 $schema['notice_tag'] = array(
426     'description' => 'Hash tags',
427     'fields' => array(
428         'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this notice'),
429         'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice tagged'),
430         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
431     ),
432     'primary key' => array('tag', 'notice_id'),
433     'foreign keys' => array(
434         'notice_id' => array('notice' => 'id'),
435     ),
436     'indexes' => array(
437         'notice_tag_created_idx' => array('created'),
438         'notice_tag_notice_id_idx' => array('notice_id'),
439     ),
440 );
441
442 /* Synching with foreign services */
443
444 $schema['foreign_service'] = array(
445     'fields' => array(
446         'id' => array('type' => 'int', 'not null' => true, 'description' => 'numeric key for service'),
447         'name' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'name of the service'),
448         'description' => array('type' => 'varchar', 'length' => 255, 'description' => 'description'),
449         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
450         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
451     ),
452     'primary key' => array('id'),
453     'unique keys' => array(
454         'foreign_service_name_idx' => array('name'),
455     ),
456 );
457
458 $schema['foreign_user'] = array(
459     'fields' => array(
460         'id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'unique numeric key on foreign service'),
461         'service' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to service'),
462         'uri' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'identifying URI'),
463         'nickname' => array('type' => 'varchar', 'length' => 255, 'description' => 'nickname on foreign service'),
464         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
465         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
466     ),
467     'primary key' => array('id', 'service'),
468     'foreign keys' => array(
469         'service' => array('foreign_service' => 'id'),
470     ),
471     'unique keys' => array(
472         'foreign_user_uri_idx' => array('uri'),
473     ),
474 );
475
476 $schema['foreign_link'] = array(
477     'fields' => array(
478         'user_id' => array('type' => 'int', 'description' => 'link to user on this system, if exists'),
479         'foreign_id' => array('type' => 'int', 'size' => 'big', 'unsigned' => true, 'description' => 'link to user on foreign service, if exists'),
480         'service' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to service'),
481         'credentials' => array('type' => 'varchar', 'length' => 255, 'description' => 'authc credentials, typically a password'),
482         'noticesync' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 1, 'description' => 'notice synchronization, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies'),
483         'friendsync' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 2, 'description' => 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'),
484         'profilesync' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 1, 'description' => 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'),
485         'last_noticesync' => array('type' => 'datetime', 'description' => 'last time notices were imported'),
486         'last_friendsync' => array('type' => 'datetime', 'description' => 'last time friends were imported'),
487         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
488         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
489     ),
490     'primary key' => array('user_id', 'foreign_id', 'service'),
491     'foreign keys' => array(
492         'user_id' => array('user' => 'id'),
493         'foreign_id' => array('foreign_user' => 'id'),
494         'service' => array('foreign_service' => 'id'),
495     ),
496     'indexes' => array(
497         'foreign_user_user_id_idx' => array('user_id'),
498     ),
499 );
500
501 $schema['foreign_subscription'] = array(
502     'fields' => array(
503         'service' => array('type' => 'int', 'not null' => true, 'description' => 'service where relationship happens'),
504         'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'subscriber on foreign service'),
505         'subscribed' => array('type' => 'int', 'not null' => true, 'description' => 'subscribed user'),
506         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
507     ),
508     'primary key' => array('service', 'subscriber', 'subscribed'),
509     'foreign keys' => array(
510         'service' => array('foreign_service' => 'id'),
511         'subscriber' => array('foreign_user' => 'id'),
512         'subscribed' => array('foreign_user' => 'id'),
513     ),
514     'indexes' => array(
515         'foreign_subscription_subscriber_idx' => array('subscriber'),
516         'foreign_subscription_subscribed_idx' => array('subscribed'),
517     ),
518 );
519
520 $schema['invitation'] = array(
521     'fields' => array(
522         'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'random code for an invitation'),
523         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'who sent the invitation'),
524         'address' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'invitation sent to'),
525         'address_type' => array('type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'),
526         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
527     ),
528     'primary key' => array('code'),
529     'foreign keys' => array(
530         'user_id' => array('user' => 'id'),
531     ),
532     'indexes' => array(
533         'invitation_address_idx' => array('address', 'address_type'),
534         'invitation_user_id_idx' => array('user_id'),
535     ),
536 );
537
538 $schema['message'] = array(
539     'fields' => array(
540         'id' => array('type' => 'serial', 'description' => 'unique identifier'),
541         'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier'),
542         'from_profile' => array('type' => 'int', 'not null' => true, 'description' => 'who the message is from'),
543         'to_profile' => array('type' => 'int', 'not null' => true, 'description' => 'who the message is to'),
544         'content' => array('type' => 'text', 'description' => 'message content'),
545         'rendered' => array('type' => 'text', 'description' => 'HTML version of the content'),
546         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of any attachment (image, video, bookmark, whatever)'),
547         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
548         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
549         'source' => array('type' => 'varchar', 'length' => 32, 'description' => 'source of comment, like "web", "im", or "clientname"'),
550     ),
551     'primary key' => array('id'),
552     'unique key' => array(
553         'message_uri_idx' => array('uri'),
554     ),
555     'foreign keys' => array(
556         'from_profile' => array('profile' => 'id'),
557         'to_profile' => array('profile' => 'id'),
558     ),
559     'indexes' => array(
560         // @fixme these are really terrible indexes, since you can only sort on one of them at a time.
561         // looks like we really need a (to_profile, created) for inbox and a (from_profile, created) for outbox
562         'message_from_idx' => array('from_profile'),
563         'message_to_idx' => array('to_profile'),
564         'message_created_idx' => array('created'),
565     ),
566 );
567
568 $schema['notice_inbox'] = array(
569     'description' => 'Obsolete; old entries here are converted to packed entries in the inbox table since 0.9',
570     'fields' => array(
571         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user receiving the message'),
572         'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice received'),
573         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice was created'),
574         'source' => array('type' => 'bool', 'default' => 1, 'description' => 'reason it is in the inbox, 1=subscription'),
575     ),
576     'primary key' => array('user_id', 'notice_id'),
577     'foreign keys' => array(
578         'user_id' => array('user' => 'id'),
579         'notice_id' => array('notice' => 'id'),
580     ),
581     'indexes' => array(
582         'notice_inbox_notice_id_idx' => array('notice_id'),
583     ),
584 );
585
586 $schema['profile_tag'] = array(
587     'fields' => array(
588         'tagger' => array('type' => 'int', 'not null' => true, 'description' => 'user making the tag'),
589         'tagged' => array('type' => 'int', 'not null' => true, 'description' => 'profile tagged'),
590         'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this notice'),
591         'modified' => array('type' => 'timestamp', 'description' => 'date the tag was added'),
592     ),
593     'primary key' => array('tagger', 'tagged', 'tag'),
594     'foreign keys' => array(
595         'tagger' => array('user' => 'id'),
596         'tagged' => array('profile' => 'id'),
597     ),
598     'indexes' => array(
599         'profile_tag_modified_idx' => array('modified'),
600         'profile_tag_tagger_tag_idx' => array('tagger', 'tag'),
601         'profile_tag_tagged_idx' => array('tagged'),
602     ),
603 );
604
605 $schema['profile_block'] = array(
606     'fields' => array(
607         'blocker' => array('type' => 'int', 'not null' => true, 'description' => 'user making the block'),
608         'blocked' => array('type' => 'int', 'not null' => true, 'description' => 'profile that is blocked'),
609         'modified' => array('type' => 'timestamp', 'description' => 'date of blocking'),
610     ),
611     'foreign keys' => array(
612         'blocker' => array('user' => 'id'),
613         'blocked' => array('profile' => 'id'),
614     ),
615     'primary key' => array('blocker', 'blocked'),
616 );
617
618 $schema['user_group'] = array(
619     'fields' => array(
620         'id' => array('type' => 'serial', 'description' => 'unique identifier'),
621
622         'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'nickname for addressing'),
623         'fullname' => array('type' => 'varchar', 'length' => 255, 'description' => 'display name'),
624         'homepage' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL, cached so we dont regenerate'),
625         'description' => array('type' => 'text', 'description' => 'group description'),
626         'location' => array('type' => 'varchar', 'length' => 255, 'description' => 'related physical location, if any'),
627
628         'original_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'original size logo'),
629         'homepage_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'homepage (profile) size logo'),
630         'stream_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'stream-sized logo'),
631         'mini_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'mini logo'),
632         'design_id' => array('type' => 'int', 'description' => 'id of a design'),
633
634         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
635         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
636
637         'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universal identifier'),
638         'mainpage' => array('type' => 'varchar', 'length' => 255, 'description' => 'page for group info to link to'),
639     ),
640     'primary key' => array('id'),
641     'unique key' => array(
642         'user_uri_idx' => array('uri'),
643     ),
644     'foreign keys' => array(
645         'design_id' => array('design' => 'id'),
646     ),
647     'indexes' => array(
648         'user_group_nickname_idx' => array('nickname'),
649     ),
650 );
651
652 $schema['group_member'] = array(
653     'fields' => array(
654         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
655         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
656         'is_admin' => array('type' => 'boolean', 'default' => false, 'description' => 'is this user an admin?'),
657
658         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
659         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
660     ),
661     'primary key' => array('group_id', 'profile_id'),
662     'foreign keys' => array(
663         'group_id' => array('user_group' => 'id'),
664         'profile_id' => array('profile' => 'id'),
665     ),
666     'indexes' => array(
667         // @fixme probably we want a (profile_id, created) index here?
668         'group_member_profile_id_idx' => array('profile_id'),
669         'group_member_created_idx' => array('created'),
670     ),
671 );
672
673 $schema['related_group'] = array(
674     // @fixme description for related_group?
675     'fields' => array(
676         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
677         'related_group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
678
679         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
680     ),
681     'primary key' => array('group_id', 'related_group_id'),
682     'foreign keys' => array(
683         'group_id' => array('user_group' => 'id'),
684         'related_group_id' => array('user_group' => 'id'),
685     ),
686 );
687
688 $schema['group_inbox'] = array(
689     'description' => 'Many-many table listing notices posted to a given group, or which groups a given notice was posted to.',
690     'fields' => array(
691         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group receiving the message'),
692         'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice received'),
693         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice was created'),
694     ),
695     'primary key' => array('group_id', 'notice_id'),
696     'foreign keys' => array(
697         'group_id' => array('user_group' => 'id'),
698         'notice_id' => array('notice' => 'id'),
699     ),
700     'indexes' => array(
701         'group_inbox_created_idx' => array('created'),
702         'group_inbox_notice_id_idx' => array('notice_id'),
703     ),
704 );
705
706 $schema['file'] = array(
707     'fields' => array(
708         'id' => array('type' => 'serial'),
709         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'destination URL after following redirections'),
710         'mimetype' => array('type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'),
711         'size' => array('type' => 'int', 'description' => 'size of resource when available'),
712         'title' => array('type' => 'varchar', 'length' => 255, 'description' => 'title of resource when available'),
713         'date' => array('type' => 'int', 'description' => 'date of resource according to http query'),
714         'protected' => array('type' => 'int', 'description' => 'true when URL is private (needs login)'),
715         'filename' => array('type' => 'varchar', 'length' => 255, 'description' => 'if a local file, name of the file'),
716
717         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
718     ),
719     'primary key' => array('id'),
720     'unique keys' => array(
721         'file_url_idx' => array('url'),
722     ),
723 );
724
725 $schema['file_oembed'] = array(
726     'fields' => array(
727         'file_id' => array('type' => 'int', 'description' => 'oEmbed for that URL/file'),
728         'version' => array('type' => 'varchar', 'length' => 20, 'description' => 'oEmbed spec. version'),
729         'type' => array('type' => 'varchar', 'length' => 20, 'description' => 'oEmbed type: photo, video, link, rich'),
730         'mimetype' => array('type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'),
731         'provider' => array('type' => 'varchar', 'length' => 50, 'description' => 'name of this oEmbed provider'),
732         'provider_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of this oEmbed provider'),
733         'width' => array('type' => 'int', 'description' => 'width of oEmbed resource when available'),
734         'height' => array('type' => 'int', 'description' => 'height of oEmbed resource when available'),
735         'html' => array('type' => 'text', 'description' => 'html representation of this oEmbed resource when applicable'),
736         'title' => array('type' => 'varchar', 'length' => 255, 'description' => 'title of oEmbed resource when available'),
737         'author_name' => array('type' => 'varchar', 'length' => 50, 'description' => 'author name for this oEmbed resource'),
738         'author_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'author URL for this oEmbed resource'),
739         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL for this oEmbed resource when applicable (photo, link)'),
740         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
741     ),
742     'primary key' => array('file_id'),
743     'foreign keys' => array(
744          'file_id' => array('file' => 'id'),
745     ),
746 );
747
748 $schema['file_redirection'] = array(
749     'fields' => array(
750         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'short URL (or any other kind of redirect) for file (id)'),
751         'file_id' => array('type' => 'int', 'description' => 'short URL for what URL/file'),
752         'redirections' => array('type' => 'int', 'description' => 'redirect count'),
753         'httpcode' => array('type' => 'int', 'description' => 'HTTP status code (20x, 30x, etc.)'),
754         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
755     ),
756     'primary key' => array('url'),
757     'foreign keys' => array(
758          'file_id' => array('file' => 'id'),
759     ),
760 );
761
762 $schema['file_thumbnail'] = array(
763     'fields' => array(
764         'file_id' => array('type' => 'int',  'description' => 'thumbnail for what URL/file'),
765         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of thumbnail'),
766         'width' => array('type' => 'int', 'description' => 'width of thumbnail'),
767         'height' => array('type' => 'int', 'description' => 'height of thumbnail'),
768         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
769     ),
770     'primary key' => array('file_id'),
771     'foreign keys' => array(
772         'file_id' => array('file' => 'id'),
773     ),
774     'unique keys' => array(
775         'file_thumbnail_url_idx' => array('url'),
776     ),
777 );
778
779 $schema['file_to_post'] = array(
780     'fields' => array(
781         'file_id' => array('type' => 'int', 'description' => 'id of URL/file'),
782         'post_id' => array('type' => 'int', 'description' => 'id of the notice it belongs to'),
783         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
784     ),
785     'primary key' => array('file_id', 'post_id'),
786     'foreign keys' => array(
787         'file_id' => array('file' => 'id'),
788         'post_id' => array('notice' => 'id'),
789     ),
790     'indexes' => array(
791         'post_id_idx' => array('post_id'),
792     ),
793 );
794
795 $schema['design'] = array(
796     'fields' => array(
797         'id' => array('type' => 'serial', 'description' => 'design ID'),
798         'backgroundcolor' => array('type' => 'int', 'description' => 'main background color'),
799         'contentcolor' => array('type' => 'int', 'description' => 'content area background color'),
800         'sidebarcolor' => array('type' => 'int', 'description' => 'sidebar background color'),
801         'textcolor' => array('type' => 'int', 'description' => 'text color'),
802         'linkcolor' => array('type' => 'int', 'description' => 'link color'),
803         'backgroundimage' => array('type' => 'varchar', 'length' => 255, 'description' => 'background image, if any'),
804         'disposition' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'bit 1 = hide background image, bit 2 = display background image, bit 4 = tile background image'),
805     ),
806     'primary key' => array('id'),
807 );
808
809 $schema['group_block'] = array(
810     'fields' => array(
811         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group profile is blocked from'),
812         'blocked' => array('type' => 'int', 'not null' => true, 'description' => 'profile that is blocked'),
813         'blocker' => array('type' => 'int', 'not null' => true, 'description' => 'user making the block'),
814         'modified' => array('type' => 'timestamp', 'description' => 'date of blocking'),
815     ),
816     'primary key' => array('group_id', 'blocked'),
817     'foreign keys' => array(
818         'group_id' => array('user_group' => 'id'),
819         'blocked' => array('profile' => 'id'),
820         'blocker' => array('user' => 'id'),
821     ),
822 );
823
824 $schema['group_alias'] = array(
825     'fields' => array(
826         'alias' => array('type' => 'varchar', 'length' => 64, 'description' => 'additional nickname for the group'),
827         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group profile is blocked from'),
828         'modified' => array('type' => 'timestamp', 'description' => 'date alias was created'),
829     ),
830     'primary key' => array('alias'),
831     'foreign keys' => array(
832         'group_id' => array('user_group' => 'id'),
833     ),
834     'indexes' => array(
835         'group_alias_group_id_idx' => array('group_id'),
836     ),
837 );
838
839 $schema['session'] = array(
840     'fields' => array(
841         'id' => array('type' => 'varchar', 'length' => 32, 'description' => 'session ID'),
842         'session_data' => array('type' => 'text', 'description' => 'session data'),
843         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
844         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
845     ),
846     'primary key' => array('id'),
847     'indexes' => array(
848         'session_modified_idx' => array('modified'),
849     ),
850 );
851
852 $schema['deleted_notice'] = array(
853     'fields' => array(
854         'id' => array('type' => 'int', 'description' => 'identity of notice'),
855         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'author of the notice'),
856         'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier, usually a tag URI'),
857         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created'),
858         'deleted' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created'),
859     ),
860     'primary key' => array('id'),
861     'unique keys' => array(
862         'deleted_notice_uri_idx' => array('uri'),
863     ),
864     'indexes' => array(
865         'deleted_notice_profile_id_idx' => array('profile_id'),
866     ),
867 );
868
869 $schema['config'] = array(
870     'fields' => array(
871         'section' => array('type' => 'varchar', 'length' => 32, 'description' => 'configuration section'),
872         'setting' => array('type' => 'varchar', 'length' => 32, 'description' => 'configuration setting'),
873         'value' => array('type' => 'varchar', 'length' => 255, 'description' => 'configuration value'),
874     ),
875     'primary key' => array('section', 'setting'),
876 );
877
878 $schema['profile_role'] = array(
879     'fields' => array(
880         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'account having the role'),
881         'role' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'string representing the role'),
882         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the role was granted'),
883     ),
884     'primary key' => array('profile_id', 'role'),
885     'foreign keys' => array(
886         'profile_id' => array('profile' => 'id'),
887     ),
888 );
889
890 $schema['location_namespace'] = array(
891     'fields' => array(
892         'id' => array('type' => 'int', 'description' => 'identity for this namespace'),
893         'description' => array('type' => 'varchar', 'length' => 255, 'description' => 'description of the namespace'),
894         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the record was created'),
895         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
896     ),
897     'primary key' => array('id'),
898 );
899
900 $schema['login_token'] = array(
901     'fields' => array(
902         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user owning this token'),
903         'token' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'token useable for logging in'),
904         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
905         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
906     ),
907     'primary key' => array('user_id'),
908     'foreign keys' => array(
909         'user_id' => array('user' => 'id'),
910     ),
911 );
912
913 $schema['user_location_prefs'] = array(
914     'fields' => array(
915         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who has the preference'),
916         'share_location' => array('type' => 'bool', 'default' => 1, 'description' => 'Whether to share location data'),
917         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
918         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
919     ),
920     'primary key' => array(user_id),
921     'foreign keys' => array(
922         'user_id' => array('user' => 'id'),
923     ),
924 );
925
926 $schema['inbox'] = array(
927     'fields' => array(
928         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user receiving the notice'),
929         'notice_ids' => array('type' => 'blob', 'description' => 'packed list of notice ids'),
930     ),
931     'primary key' => array('user_id'),
932     'foreign keys' => array(
933         'user_id' => array('user' => 'id'),
934     ),
935 );
936
937 // @fixme possibly swap this for a more general prefs table?
938 $schema['user_im_prefs'] = array(
939     'fields' => array(
940         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user'),
941         'screenname' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'screenname on this service'),
942         'transport' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'transport (ex xmpp, aim)'),
943         'notify' => array('type' => 'bool', 'not null' => true, 'default' => 0, 'description' => 'Notify when a new notice is sent'),
944         'replies' => array('type' => 'bool', 'not null' => true, 'default' => 0, 'description' => 'Send replies  from people not subscribed to'),
945         'microid' => array('type' => 'bool', 'not null' => true, 'default' => 1, 'description' => 'Publish a MicroID'),
946         'updatefrompresence' => array('type' => 'bool', 'not null' => true, 'default' => 0, 'description' => 'Send replies from people not subscribed to.'),
947         'created' => array('type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'), // @fixme will that default work?
948         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
949     ),
950     'primary key' => array('user_id', 'transport'),
951     'unique keys' => array(
952         'transport_screenname_key' => array('transport', 'screenname'),
953     ),
954     'foreign keys' => array(
955         'user_id' => array('user' => 'id'),
956     ),
957 );
958
959 $schema['conversation'] = array(
960     'fields' => array(
961         'id' => array('type' => 'serial', 'description' => 'unique identifier'),
962         'uri' => array('type' => 'varchar', 'length' => 225, 'description' => 'URI of the conversation'),
963         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
964         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
965     ),
966     'primary key' => array('id'),
967     'unique keys' => array(
968         'conversation_uri_idx' => array('uri'),
969     ),
970 );
971
972 $schema['local_group'] = array(
973     'description' => 'Record for a user group on the local site, with some additional info not in user_group',
974     'fields' => array(
975         'group_id' => array('type' => 'int', 'description' => 'group represented'),
976         'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'group represented'),
977
978         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
979         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
980     ),
981     'primary key' => array('group_id'),
982     'foreign keys' => array(
983         'group_id' => array('user_group' => 'id'),
984     ),
985     'unique keys' => array(
986         'local_group_nickname_idx' => array('nickname'),
987     ),
988 );
989
990 $schema['user_urlshortener_prefs'] = array(
991     'fields' => array(
992         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user'),
993         'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'ur1.ca', 'description' => 'service to use for auto-shortening URLs'),
994         'maxurllength' => array('type' => 'int', 'not null' => true, 'description' => 'urls greater than this length will be shortened, 0 = always, null = never'),
995         'maxnoticelength' => array('type' => 'int', 'not null' => true, 'description' => 'notices with content greater than this value will have all urls shortened, 0 = always, null = never'),
996         
997         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
998         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
999     ),
1000     'primary key' => array('user_id'),
1001     'foreign keys' => array(
1002         'user_id' => array('user' => 'id'),
1003     ),
1004 );