]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - db/core.php
work in progress
[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', comment '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('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' => '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' => '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' references foreign_user(id),
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         'service' => array('foreign_service' => 'id'),
493     ),
494     'indexes' => array(
495         'foreign_user_user_id_idx' => array('user_id'),
496     ),
497 );
498
499 $schema['foreign_subscription'] = array(
500     'fields' => array(
501         'service', 'type' => 'int', 'not null' => true, 'description' => 'service where relationship happens'),
502         'subscriber', 'type' => 'int', 'not null' => true, 'description' => 'subscriber on foreign service'),
503         'subscribed', 'type' => 'int', 'not null' => true, 'description' => 'subscribed user'),
504         'created', 'type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
505     ),
506     'primary key' => array('service', 'subscriber', 'subscribed'),
507     'foreign keys' => array(
508         'service' => array('foreign_service' => 'id'),
509         'subscriber' => array('foreign_user' => 'id'),
510         'subscribed' => array('foreign_user' => 'id'),
511     ),
512     'indexes' => array(
513         'foreign_subscription_subscriber_idx' => array('subscriber'),
514         'foreign_subscription_subscribed_idx' => array('subscribed'),
515     ),
516 );
517
518 $schema['invitation'] = array(
519     'fields' => array(
520         'code', 'type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'random code for an invitation'),
521         'user_id', 'type' => 'int', 'not null' => true, 'description' => 'who sent the invitation',
522         'address', 'type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'invitation sent to'),
523         'address_type', 'type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'),
524         'created', 'type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
525     ),
526     'primary key' => array('code'),
527     'foreign keys' => array(
528         'user_id' => array('user' => 'id'),
529     ),
530     'indexes' => array(
531         'invitation_address_idx' => array('address', 'address_type'),
532         'invitation_user_id_idx' => array('user_id'),
533     ),
534 );
535
536 $schema['message'] = array(
537     'fields' => array(
538         'id' => array('type' => 'serial', 'description' => 'unique identifier'),
539         'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier'),
540         'from_profile' => array('type' => 'int', 'not null' => true, 'description' => 'who the message is from'),
541         'to_profile' => array('type' => 'int', 'not null' => true, 'description' => 'who the message is to'),
542         'content' => array('type' => 'text', 'description' => 'message content'),
543         'rendered' => array('type' => 'text', 'description' => 'HTML version of the content'),
544         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of any attachment (image, video, bookmark, whatever)'),
545         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
546         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
547         'source' => array('type' => 'varchar', 'length' => 32, 'description' => 'source of comment, like "web", "im", or "clientname"'),
548     ),
549     'primary key' => array('id'),
550     'unique key' => array(
551         'message_uri_idx' => array('uri'),
552     ),
553     'foreign keys' => array(
554         'from_profile' => array('profile' => 'id'),
555         'to_profile' => array('profile' => 'id'),
556     ),
557     'indexes' => array(
558         // @fixme these are really terrible indexes, since you can only sort on one of them at a time.
559         // looks like we really need a (to_profile, created) for inbox and a (from_profile, created) for outbox
560         'message_from_idx' => array('from_profile'),
561         'message_to_idx' => array('to_profile'),
562         'message_created_idx' => array('created'),
563     ),
564 );
565
566 $schema['notice_inbox'] = array(
567     'description' => 'Obsolete; old entries here are converted to packed entries in the inbox table since 0.9',
568     'fields' => array(
569         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user receiving the message'),
570         'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice received'),
571         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice was created'),
572         'source' => array('type' => 'bool', 'default' => 1, 'description' => 'reason it is in the inbox, 1=subscription'),
573     ),
574     'primary key' => array('user_id', 'notice_id'),
575     'foreign keys' => array(
576         'user_id' => array('user' => 'id'),
577         'notice_id' => array('notice' => 'id'),
578     ),
579     'indexes' => array(
580         'notice_inbox_notice_id_idx' => array('notice_id'),
581     ),
582 );
583
584 $schema['profile_tag'] = array(
585     'fields' => array(
586         'tagger' => array('type' => 'int', 'not null' => true, 'description' => 'user making the tag' references user (id),
587         'tagged' => array('type' => 'int', 'not null' => true, 'description' => 'profile tagged' references profile (id),
588         'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this notice'),
589         'modified' => array('type' => 'timestamp', 'description' => 'date the tag was added'),
590     ),
591     'primary key' => array('tagger', 'tagged', 'tag'),
592     'indexes' => array(
593         'profile_tag_modified_idx' => array('modified'),
594         'profile_tag_tagger_tag_idx' => array('tagger', 'tag'),
595         'profile_tag_tagged_idx' => array('tagged'),
596     ),
597 );
598
599 $schema['profile_block'] = array(
600     'fields' => array(
601         'blocker' => array('type' => 'int', 'not null' => true, 'description' => 'user making the block' references user (id),
602         'blocked' => array('type' => 'int', 'not null' => true, 'description' => 'profile that is blocked' references profile (id),
603         'modified' => array('type' => 'timestamp', 'description' => 'date of blocking'),
604     ),
605     'primary key' => array('blocker', 'blocked'),
606 );
607
608 $schema['user_group'] = array(
609     'fields' => array(
610         'id' => array('type' => 'serial', 'description' => 'unique identifier'),
611
612         'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'nickname for addressing'),
613         'fullname' => array('type' => 'varchar', 'length' => 255, 'description' => 'display name'),
614         'homepage' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL, cached so we dont regenerate'),
615         'description' => array('type' => 'text', 'description' => 'group description'),
616         'location' => array('type' => 'varchar', 'length' => 255, 'description' => 'related physical location, if any'),
617
618         'original_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'original size logo'),
619         'homepage_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'homepage (profile) size logo'),
620         'stream_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'stream-sized logo'),
621         'mini_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'mini logo'),
622         'design_id' => array('type' => 'int', 'description' => 'id of a design' references design(id),
623
624         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
625         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
626
627         'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universal identifier'),
628         'mainpage' => array('type' => 'varchar', 'length' => 255, 'description' => 'page for group info to link to'),
629     ),
630     'primary key' => array('id'),
631     'unique key' => array(
632         'user_uri_idx' => array('uri'),
633     ),
634     'indexes' => array(
635         'user_group_nickname_idx' => array('nickname'),
636     ),
637 );
638
639 $schema['group_member'] = array(
640     'fields' => array(
641         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group' references user_group (id),
642         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table' references profile (id),
643         'is_admin' => array('type' => 'boolean', 'default' => false, 'description' => 'is this user an admin?'),
644
645         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
646         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
647     ),
648     'primary key' => array('group_id', 'profile_id'),
649     'indexes' => array(
650         // @fixme probably we want a (profile_id, created) index here?
651         'group_member_profile_id_idx' => array('profile_id'),
652         'group_member_created_idx' => array('created'),
653     ),
654 );
655
656 $schema['related_group'] = array(
657     'fields' => array(
658         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group' references user_group (id),
659         'related_group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group' references user_group (id),
660
661         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
662     ),
663     'primary key' => array('group_id', 'related_group_id'),
664 );
665
666 $schema['group_inbox'] = array(
667     'fields' => array(
668         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group receiving the message' references user_group (id),
669         'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice received' references notice (id),
670         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice was created'),
671     ),
672     'primary key' => array('group_id', 'notice_id'),
673     'indexes' => array(
674         'group_inbox_created_idx' => array('created'),
675         'group_inbox_notice_id_idx' => array('notice_id'),
676     ),
677 );
678
679 $schema['file'] = array(
680     'fields' => array(
681         'id' => array('type' => 'serial'),
682         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'destination URL after following redirections'),
683         'mimetype' => array('type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'),
684         'size' => array('type' => 'int', 'description' => 'size of resource when available'),
685         'title' => array('type' => 'varchar', 'length' => 255, 'description' => 'title of resource when available'),
686         'date' => array('type' => 'int', 'description' => 'date of resource according to http query'),
687         'protected' => array('type' => 'int', 'description' => 'true when URL is private (needs login)'),
688         'filename' => array('type' => 'varchar', 'length' => 255, 'description' => 'if a local file, name of the file'),
689
690         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
691     ),
692     'primary key' => array('id'),
693     'unique keys' => array(
694         'file_url_idx' => array('url'),
695     ),
696 );
697
698 $schema['file_oembed'] = array(
699     'fields' => array(
700         'file_id' => array('type' => 'int', 'description' => 'oEmbed for that URL/file' references file (id),
701         'version' => array('type' => 'varchar', 'length' => 20, 'description' => 'oEmbed spec. version'),
702         'type' => array('type' => 'varchar', 'length' => 20, 'description' => 'oEmbed type: photo, video, link, rich'),
703         'mimetype' => array('type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'),
704         'provider' => array('type' => 'varchar', 'length' => 50, 'description' => 'name of this oEmbed provider'),
705         'provider_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of this oEmbed provider'),
706         'width' => array('type' => 'int', 'description' => 'width of oEmbed resource when available'),
707         'height' => array('type' => 'int', 'description' => 'height of oEmbed resource when available'),
708         'html' => array('type' => 'text', 'description' => 'html representation of this oEmbed resource when applicable'),
709         'title' => array('type' => 'varchar', 'length' => 255, 'description' => 'title of oEmbed resource when available'),
710         'author_name' => array('type' => 'varchar', 'length' => 50, 'description' => 'author name for this oEmbed resource'),
711         'author_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'author URL for this oEmbed resource'),
712         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL for this oEmbed resource when applicable (photo, link)'),
713         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'
714     ),
715     'primary key' => array('file_id'),
716 );
717
718 $schema['file_redirection'] = array(
719     'fields' => array(
720         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'short URL (or any other kind of redirect) for file (id)'),
721         'file_id' => array('type' => 'int', 'description' => 'short URL for what URL/file' references file (id),
722         'redirections' => array('type' => 'int', 'description' => 'redirect count'),
723         'httpcode' => array('type' => 'int', 'description' => 'HTTP status code (20x, 30x, etc.)'),
724         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'
725     ),
726     'primary key' => array('url'),
727 );
728
729 $schema['file_thumbnail'] = array(
730     'fields' => array(
731         'file_id' => array('type' => 'int',  'description' => 'thumbnail for what URL/file' references file (id),
732         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of thumbnail'),
733         'width' => array('type' => 'int', 'description' => 'width of thumbnail'),
734         'height' => array('type' => 'int', 'description' => 'height of thumbnail'),
735         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
736     'primary key' => array('file_id'),
737     'unique keys' => array(
738         'file_thumbnail_url_idx' => array('url'),
739     ),
740 );
741
742 $schema['file_to_post'] = array(
743     'fields' => array(
744         'file_id' => array('type' => 'int', 'description' => 'id of URL/file' references file (id),
745         'post_id' => array('type' => 'int', 'description' => 'id of the notice it belongs to' references notice (id),
746         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
747     ),
748     'primary key' => array('file_id', 'post_id'),
749     'indexes' => array(
750         'post_id_idx' => array('post_id'),
751     ),
752 );
753
754 $schema['design'] = array(
755     'fields' => array(
756         'id' => array('type' => 'serial', 'description' => 'design ID'),
757         'backgroundcolor' => array('type' => 'int', 'description' => 'main background color'),
758         'contentcolor' => array('type' => 'int', 'description' => 'content area background color'),
759         'sidebarcolor' => array('type' => 'int', 'description' => 'sidebar background color'),
760         'textcolor' => array('type' => 'int', 'description' => 'text color'),
761         'linkcolor' => array('type' => 'int', 'description' => 'link color'),
762         'backgroundimage' => array('type' => 'varchar', 'length' => 255, 'description' => 'background image, if any'),
763         'disposition' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'bit 1 = hide background image, bit 2 = display background image, bit 4 = tile background image'
764     ),
765     'primary key' => array('id'),
766 );
767
768 $schema['group_block'] = array(
769     'fields' => array(
770         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group profile is blocked from' references user_group (id),
771         'blocked' => array('type' => 'int', 'not null' => true, 'description' => 'profile that is blocked' references profile (id),
772         'blocker' => array('type' => 'int', 'not null' => true, 'description' => 'user making the block' references user (id),
773         'modified' => array('type' => 'timestamp', 'description' => 'date of blocking'),
774     ),
775     'primary key' => array('group_id', 'blocked'),
776 );
777
778 $schema['group_alias'] = array(
779     'fields' => array(
780         'alias' => array('type' => 'varchar', 'length' => 64, 'description' => 'additional nickname for the group'),
781         'group_id' => array('type' => 'int 'not null' => true, 'description' => 'group profile is blocked from' references user_group (id),
782         'modified' => array('type' => 'timestamp 'description' => 'date alias was created'),
783     'primary key' => array('alias'),
784     'indexes' => array(
785         'group_alias_group_id_idx' => array('group_id'),
786     ),
787 );
788
789 $schema['session'] = array(
790     'fields' => array(
791         'id' => array('type' => 'varchar', 'length' => 32, primary key 'description' => 'session ID'),
792         'session_data' => array('type' => 'text', 'description' => 'session data'),
793         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
794         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
795
796     'indexes' => array(
797     index session_modified_idx (modified)
798
799 );
800
801 $schema['deleted_notice'] = array(
802     'fields' => array(
803         'id' => array('type' => 'int', primary key 'description' => 'identity of notice'),
804         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'author of the notice'),
805         'uri' => array('type' => 'varchar', 'length' => 255, unique key 'description' => 'universally unique identifier, usually a tag URI'),
806         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created'),
807         'deleted' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created'),
808
809     'indexes' => array(
810     index deleted_notice_profile_id_idx (profile_id)
811
812 );
813
814 $schema['config'] = array(
815     'fields' => array(
816         'section' => array('type' => 'varchar', 'length' => 32, 'description' => 'configuration section'),
817         'setting' => array('type' => 'varchar', 'length' => 32, 'description' => 'configuration setting'),
818         'value' => array('type' => 'varchar', 'length' => 255, 'description' => 'configuration value'),
819
820     'primary key' => array(section, setting)
821
822 );
823
824 $schema['profile_role'] = array(
825     'fields' => array(
826         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'account having the role' references profile (id),
827         'role   ', 'type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'string representing the role'),
828         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the role was granted'),
829
830     'primary key' => array(profile_id, role)
831
832 );
833
834 $schema['location_namespace'] = array(
835     'fields' => array(
836         'id' => array('type' => 'int', primary key 'description' => 'identity for this namespace'),
837         'description' => array('type' => 'varchar', 'length' => 255, 'description' => 'description of the namespace'),
838         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the record was created'),
839         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'
840
841 );
842
843 $schema['login_token'] = array(
844     'fields' => array(
845         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user owning this token' references user (id),
846         'token' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'token useable for logging in'),
847         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
848         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
849
850     'primary key' => array(user_id)
851 );
852
853 $schema['user_location_prefs'] = array(
854     'fields' => array(
855         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who has the preference' references user (id),
856         'share_location' => array('type' => 'bool', 'default' => 1, 'description' => 'Whether to share location data'),
857         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
858         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
859     ),
860     'primary key' => array(user_id)
861 );
862
863 $schema['inbox'] = array(
864     'fields' => array(
865         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user receiving the notice' references user (id),
866         'notice_ids' => array('type' => 'blob', 'description' => 'packed list of notice ids'),
867     ),
868     'primary key' => array(user_id)
869
870 );
871
872 // @fixme possibly swap this for a more general prefs table?
873 $schema['user_im_prefs'] = array(
874     'fields' => array(
875         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user',
876         'screenname' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'screenname on this service'),
877         'transport' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'transport (ex xmpp, aim)'),
878         'notify' => array('type' => 'bool', 'not null' => true, 'default' => 0, 'description' => 'Notify when a new notice is sent'),
879         'replies' => array('type' => 'bool', 'not null' => true, 'default' => 0, 'description' => 'Send replies  from people not subscribed to'),
880         'microid' => array('type' => 'bool', 'not null' => true, 'default' => 1, 'description' => 'Publish a MicroID'),
881         'updatefrompresence' => array('type' => 'bool', 'not null' => true, 'default' => 0, 'description' => 'Send replies  from people not subscribed to.'),
882         'created' => array('type' => 'timestamp', 'not null' => true, DEFAULT CURRENT_TIMESTAMP 'description' => 'date this record was created'),
883         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
884
885     'primary key' => array('user_id', 'transport'),
886     'unique keys' => array(
887         'transport_screenname_key' => array('transport', 'screenname'),
888     ),
889     'foreign keys' => array(
890         'user_id' => array('user' => 'id'),
891     ),
892 );
893
894 $schema['conversation'] = array(
895     'fields' => array(
896         'id' => array('type' => 'serial', 'description' => 'unique identifier'),
897         'uri' => array('type' => 'varchar', 'length' => 225, 'description' => 'URI of the conversation'),
898         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
899         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'
900     ),
901     'primary key' => array('id'),
902     'unique keys' => array(
903         'conversation_uri_idx' => array('uri'),
904     ),
905 );
906
907 $schema['local_group'] = array(
908     'description' => 'Record for a user group on the local site, with some additional info not in user_group',
909     'fields' => array(
910         'group_id' => array('type' => 'int', 'description' => 'group represented'),
911         'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'group represented'),
912
913         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
914         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'
915     ),
916     'primary key' => array('group_id'),
917     'foreign keys' => array(
918         'group_id' => array('user_group' => 'id'),
919     ),
920     'unique keys' => array(
921         'local_group_nickname_idx' => array('nickname'),
922     ),
923 );
924
925 $schema['user_urlshortener_prefs'] = array(
926     'fields' => array(
927         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user'),
928         'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'ur1.ca', 'description' => 'service to use for auto-shortening URLs'),
929         'maxurllength' => array('type' => 'int', 'not null' => true, 'description' => 'urls greater than this length will be shortened, 0 = always, null = never'),
930         'maxnoticelength' => array('type' => 'int', 'not null' => true, 'description' => 'notices with content greater than this value will have all urls shortened, 0 = always, null = never'),
931         
932         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
933         'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
934
935    'primary key' => array('user_id'),
936    'foreign keys' => array(
937         'user_id' => array('user' => 'id'),
938    ),
939 );