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