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