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