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