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