]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - db/core.php
Merge remote-tracking branch 'mainline/1.0.x' into people_tags_rebase
[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('profile', array('tagger' => 'id')),
609         'profile_tag_tagged_fkey' => array('profile', array('tagged' => 'id')),
610         'profile_tag_tag_fkey' => array('profile_list', array('tag' => 'tag')),
611     ),
612     'indexes' => array(
613         'profile_tag_modified_idx' => array('modified'),
614         'profile_tag_tagger_tag_idx' => array('tagger', 'tag'),
615         'profile_tag_tagged_idx' => array('tagged'),
616     ),
617 );
618
619 $schema['profile_list'] = array(
620     'fields' => array(
621         'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
622         'tagger' => array('type' => 'int', 'not null' => true, 'description' => 'user making the tag'),
623         'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'people tag'),
624         'description' => array('type' => 'text', 'description' => 'description of the people tag'),
625         'private' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'is this tag private'),
626
627         'created' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date the tag was added'),
628         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date the tag was modified'),
629
630         'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universal identifier'),
631         'mainpage' => array('type' => 'varchar', 'length' => 255, 'description' => 'page to link to'),
632         'tagged_count' => array('type' => 'int', 'default' => 0, 'description' => 'number of people tagged with this tag by this user'),
633         'subscriber_count' => array('type' => 'int', 'default' => 0, 'description' => 'number of subscribers to this tag'),
634     ),
635     'primary key' => array('tagger', 'tag'),
636     'unique keys' => array(
637       'profile_list_id_key' => array('id')
638     ),
639     'foreign keys' => array(
640         'profile_list_tagger_fkey' => array('profile', array('tagger' => 'id')),
641     ),
642     'indexes' => array(
643         'profile_list_modified_idx' => array('modified'),
644         'profile_list_tag_idx' => array('tag'),
645         'profile_list_tagger_tag_idx' => array('tagger', 'tag'),
646         'profile_list_tagged_count_idx' => array('tagged_count'),
647         'profile_list_subscriber_count_idx' => array('subscriber_count'),
648     ),
649 );
650
651 $schema['profile_tag_inbox'] = array(
652     'description' => 'Many-many table listing notices associated with people tags.',
653     'fields' => array(
654         'profile_tag_id' => array('type' => 'int', 'not null' => true, 'description' => 'people tag receiving the message'),
655         'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice received'),
656         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice was created'),
657     ),
658     'primary key' => array('profile_tag_id', 'notice_id'),
659     'foreign keys' => array(
660         'profile_tag_inbox_profile_list_id_fkey' => array('profile_list', array('profile_tag_id' => 'id')),
661         'profile_tag_inbox_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
662     ),
663     'indexes' => array(
664         'profile_tag_inbox_created_idx' => array('created'),
665         'profile_tag_inbox_profile_tag_id_idx' => array('profile_tag_id'),
666     ),
667 );
668
669 $schema['profile_tag_subscription'] = array(
670     'fields' => array(
671         'profile_tag_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile_tag'),
672         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
673
674         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
675         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
676     ),
677     'primary key' => array('profile_tag_id', 'profile_id'),
678     'foreign keys' => array(
679         'profile_tag_subscription_profile_list_id_fkey' => array('profile_list', array('profile_tag_id' => 'id')),
680         'profile_tag_subscription_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
681     ),
682     'indexes' => array(
683         // @fixme probably we want a (profile_id, created) index here?
684         'profile_tag_subscription_profile_id_idx' => array('profile_id'),
685         'profile_tag_subscription_created_idx' => array('created'),
686     ),
687 );
688
689 $schema['profile_block'] = array(
690     'fields' => array(
691         'blocker' => array('type' => 'int', 'not null' => true, 'description' => 'user making the block'),
692         'blocked' => array('type' => 'int', 'not null' => true, 'description' => 'profile that is blocked'),
693         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date of blocking'),
694     ),
695     'foreign keys' => array(
696         'profile_block_blocker_fkey' => array('user', array('blocker' => 'id')),
697         'profile_block_blocked_fkey' => array('profile', array('blocked' => 'id')),
698     ),
699     'primary key' => array('blocker', 'blocked'),
700 );
701
702 $schema['user_group'] = array(
703     'fields' => array(
704         'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
705
706         'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'nickname for addressing'),
707         'fullname' => array('type' => 'varchar', 'length' => 255, 'description' => 'display name'),
708         'homepage' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL, cached so we dont regenerate'),
709         'description' => array('type' => 'text', 'description' => 'group description'),
710         'location' => array('type' => 'varchar', 'length' => 255, 'description' => 'related physical location, if any'),
711
712         'original_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'original size logo'),
713         'homepage_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'homepage (profile) size logo'),
714         'stream_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'stream-sized logo'),
715         'mini_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'mini logo'),
716         'design_id' => array('type' => 'int', 'description' => 'id of a design'),
717
718         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
719         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
720
721         'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universal identifier'),
722         'mainpage' => array('type' => 'varchar', 'length' => 255, 'description' => 'page for group info to link to'),
723         'join_policy' => array('type' => 'int', 'size' => 'tiny', 'description' => '0=open; 1=requires admin approval'),
724     ),
725     'primary key' => array('id'),
726     'unique keys' => array(
727         'user_group_uri_key' => array('uri'),
728     ),
729     'foreign keys' => array(
730         'user_group_design_id_fkey' => array('design', array('design_id' => 'id')),
731     ),
732     'indexes' => array(
733         'user_group_nickname_idx' => array('nickname'),
734     ),
735 );
736
737 $schema['group_member'] = array(
738     'fields' => array(
739         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
740         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
741         'is_admin' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'is this user an admin?'),
742
743         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
744         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
745     ),
746     'primary key' => array('group_id', 'profile_id'),
747     'foreign keys' => array(
748         'group_member_group_id_fkey' => array('user_group', array('group_id' => 'id')),
749         'group_member_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
750     ),
751     'indexes' => array(
752         // @fixme probably we want a (profile_id, created) index here?
753         'group_member_profile_id_idx' => array('profile_id'),
754         'group_member_created_idx' => array('created'),
755     ),
756 );
757
758 $schema['related_group'] = array(
759     // @fixme description for related_group?
760     'fields' => array(
761         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
762         'related_group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
763
764         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
765     ),
766     'primary key' => array('group_id', 'related_group_id'),
767     'foreign keys' => array(
768         'related_group_group_id_fkey' => array('user_group', array('group_id' => 'id')),
769         'related_group_related_group_id_fkey' => array('user_group', array('related_group_id' => 'id')),
770     ),
771 );
772
773 $schema['group_inbox'] = array(
774     'description' => 'Many-many table listing notices posted to a given group, or which groups a given notice was posted to.',
775     'fields' => array(
776         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group receiving the message'),
777         'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice received'),
778         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice was created'),
779     ),
780     'primary key' => array('group_id', 'notice_id'),
781     'foreign keys' => array(
782         'group_inbox_group_id_fkey' => array('user_group', array('group_id' => 'id')),
783         'group_inbox_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
784     ),
785     'indexes' => array(
786         'group_inbox_created_idx' => array('created'),
787         'group_inbox_notice_id_idx' => array('notice_id'),
788     ),
789 );
790
791 $schema['file'] = array(
792     'fields' => array(
793         'id' => array('type' => 'serial', 'not null' => true),
794         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'destination URL after following redirections'),
795         'mimetype' => array('type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'),
796         'size' => array('type' => 'int', 'description' => 'size of resource when available'),
797         'title' => array('type' => 'varchar', 'length' => 255, 'description' => 'title of resource when available'),
798         'date' => array('type' => 'int', 'description' => 'date of resource according to http query'),
799         'protected' => array('type' => 'int', 'description' => 'true when URL is private (needs login)'),
800         'filename' => array('type' => 'varchar', 'length' => 255, 'description' => 'if a local file, name of the file'),
801
802         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
803     ),
804     'primary key' => array('id'),
805     'unique keys' => array(
806         'file_url_key' => array('url'),
807     ),
808 );
809
810 $schema['file_oembed'] = array(
811     'fields' => array(
812         'file_id' => array('type' => 'int', 'not null' => true, 'description' => 'oEmbed for that URL/file'),
813         'version' => array('type' => 'varchar', 'length' => 20, 'description' => 'oEmbed spec. version'),
814         'type' => array('type' => 'varchar', 'length' => 20, 'description' => 'oEmbed type: photo, video, link, rich'),
815         'mimetype' => array('type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'),
816         'provider' => array('type' => 'varchar', 'length' => 50, 'description' => 'name of this oEmbed provider'),
817         'provider_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of this oEmbed provider'),
818         'width' => array('type' => 'int', 'description' => 'width of oEmbed resource when available'),
819         'height' => array('type' => 'int', 'description' => 'height of oEmbed resource when available'),
820         'html' => array('type' => 'text', 'description' => 'html representation of this oEmbed resource when applicable'),
821         'title' => array('type' => 'varchar', 'length' => 255, 'description' => 'title of oEmbed resource when available'),
822         'author_name' => array('type' => 'varchar', 'length' => 50, 'description' => 'author name for this oEmbed resource'),
823         'author_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'author URL for this oEmbed resource'),
824         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL for this oEmbed resource when applicable (photo, link)'),
825         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
826     ),
827     'primary key' => array('file_id'),
828     'foreign keys' => array(
829          'file_oembed_file_id_fkey' => array('file', array('file_id' => 'id')),
830     ),
831 );
832
833 $schema['file_redirection'] = array(
834     'fields' => array(
835         'url' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'short URL (or any other kind of redirect) for file (id)'),
836         'file_id' => array('type' => 'int', 'description' => 'short URL for what URL/file'),
837         'redirections' => array('type' => 'int', 'description' => 'redirect count'),
838         'httpcode' => array('type' => 'int', 'description' => 'HTTP status code (20x, 30x, etc.)'),
839         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
840     ),
841     'primary key' => array('url'),
842     'foreign keys' => array(
843          'file_redirection_file_id_fkey' => array('file' => array('file_id' => 'id')),
844     ),
845 );
846
847 $schema['file_thumbnail'] = array(
848     'fields' => array(
849         'file_id' => array('type' => 'int', 'not null' => true, 'description' => 'thumbnail for what URL/file'),
850         'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of thumbnail'),
851         'width' => array('type' => 'int', 'description' => 'width of thumbnail'),
852         'height' => array('type' => 'int', 'description' => 'height of thumbnail'),
853         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
854     ),
855     'primary key' => array('file_id'),
856     'foreign keys' => array(
857         'file_thumbnail_file_id_fkey' => array('file', array('file_id' => 'id')),
858     ),
859     'unique keys' => array(
860         'file_thumbnail_url_key' => array('url'),
861     ),
862 );
863
864 $schema['file_to_post'] = array(
865     'fields' => array(
866         'file_id' => array('type' => 'int', 'not null' => true, 'description' => 'id of URL/file'),
867         'post_id' => array('type' => 'int', 'not null' => true, 'description' => 'id of the notice it belongs to'),
868         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
869     ),
870     'primary key' => array('file_id', 'post_id'),
871     'foreign keys' => array(
872         'file_to_post_file_id_fkey' => array('file', array('file_id' => 'id')),
873         'file_to_post_post_id_fkey' => array('notice', array('post_id' => 'id')),
874     ),
875     'indexes' => array(
876         'post_id_idx' => array('post_id'),
877     ),
878 );
879
880 $schema['design'] = array(
881     'fields' => array(
882         'id' => array('type' => 'serial', 'not null' => true, 'description' => 'design ID'),
883         'backgroundcolor' => array('type' => 'int', 'description' => 'main background color'),
884         'contentcolor' => array('type' => 'int', 'description' => 'content area background color'),
885         'sidebarcolor' => array('type' => 'int', 'description' => 'sidebar background color'),
886         'textcolor' => array('type' => 'int', 'description' => 'text color'),
887         'linkcolor' => array('type' => 'int', 'description' => 'link color'),
888         'backgroundimage' => array('type' => 'varchar', 'length' => 255, 'description' => 'background image, if any'),
889         'disposition' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'bit 1 = hide background image, bit 2 = display background image, bit 4 = tile background image'),
890     ),
891     'primary key' => array('id'),
892 );
893
894 $schema['group_block'] = array(
895     'fields' => array(
896         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group profile is blocked from'),
897         'blocked' => array('type' => 'int', 'not null' => true, 'description' => 'profile that is blocked'),
898         'blocker' => array('type' => 'int', 'not null' => true, 'description' => 'user making the block'),
899         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date of blocking'),
900     ),
901     'primary key' => array('group_id', 'blocked'),
902     'foreign keys' => array(
903         'group_block_group_id_fkey' => array('user_group', array('group_id' => 'id')),
904         'group_block_blocked_fkey' => array('profile', array('blocked' => 'id')),
905         'group_block_blocker_fkey' => array('user', array('blocker' => 'id')),
906     ),
907 );
908
909 $schema['group_alias'] = array(
910     'fields' => array(
911         'alias' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'additional nickname for the group'),
912         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group profile is blocked from'),
913         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date alias was created'),
914     ),
915     'primary key' => array('alias'),
916     'foreign keys' => array(
917         'group_alias_group_id_fkey' => array('user_group', array('group_id' => 'id')),
918     ),
919     'indexes' => array(
920         'group_alias_group_id_idx' => array('group_id'),
921     ),
922 );
923
924 $schema['session'] = array(
925     'fields' => array(
926         'id' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'session ID'),
927         'session_data' => array('type' => 'text', 'description' => 'session data'),
928         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
929         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
930     ),
931     'primary key' => array('id'),
932     'indexes' => array(
933         'session_modified_idx' => array('modified'),
934     ),
935 );
936
937 $schema['deleted_notice'] = array(
938     'fields' => array(
939         'id' => array('type' => 'int', 'not null' => true, 'description' => 'identity of notice'),
940         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'author of the notice'),
941         'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier, usually a tag URI'),
942         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created'),
943         'deleted' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created'),
944     ),
945     'primary key' => array('id'),
946     'unique keys' => array(
947         'deleted_notice_uri_key' => array('uri'),
948     ),
949     'indexes' => array(
950         'deleted_notice_profile_id_idx' => array('profile_id'),
951     ),
952 );
953
954 $schema['config'] = array(
955     'fields' => array(
956         'section' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'default' => '', 'description' => 'configuration section'),
957         'setting' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'default' => '', 'description' => 'configuration setting'),
958         'value' => array('type' => 'varchar', 'length' => 255, 'description' => 'configuration value'),
959     ),
960     'primary key' => array('section', 'setting'),
961 );
962
963 $schema['profile_role'] = array(
964     'fields' => array(
965         'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'account having the role'),
966         'role' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'string representing the role'),
967         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the role was granted'),
968     ),
969     'primary key' => array('profile_id', 'role'),
970     'foreign keys' => array(
971         'profile_role_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
972     ),
973 );
974
975 $schema['location_namespace'] = array(
976     'fields' => array(
977         'id' => array('type' => 'int', 'not null' => true, 'description' => 'identity for this namespace'),
978         'description' => array('type' => 'varchar', 'length' => 255, 'description' => 'description of the namespace'),
979         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the record was created'),
980         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
981     ),
982     'primary key' => array('id'),
983 );
984
985 $schema['login_token'] = array(
986     'fields' => array(
987         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user owning this token'),
988         'token' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'token useable for logging in'),
989         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
990         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
991     ),
992     'primary key' => array('user_id'),
993     'foreign keys' => array(
994         'login_token_user_id_fkey' => array('user', array('user_id' => 'id')),
995     ),
996 );
997
998 $schema['user_location_prefs'] = array(
999     'fields' => array(
1000         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who has the preference'),
1001         'share_location' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Whether to share location data'),
1002         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
1003         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
1004     ),
1005     'primary key' => array('user_id'),
1006     'foreign keys' => array(
1007         'user_location_prefs_user_id_fkey' => array('user', array('user_id' => 'id')),
1008     ),
1009 );
1010
1011 $schema['inbox'] = array(
1012     'fields' => array(
1013         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user receiving the notice'),
1014         'notice_ids' => array('type' => 'blob', 'description' => 'packed list of notice ids'),
1015     ),
1016     'primary key' => array('user_id'),
1017     'foreign keys' => array(
1018         'inbox_user_id_fkey' => array('user', array('user_id' => 'id')),
1019     ),
1020 );
1021
1022 // @fixme possibly swap this for a more general prefs table?
1023 $schema['user_im_prefs'] = array(
1024     'fields' => array(
1025         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user'),
1026         'screenname' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'screenname on this service'),
1027         'transport' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'transport (ex xmpp, aim)'),
1028         'notify' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 0, 'description' => 'Notify when a new notice is sent'),
1029         'replies' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 0, 'description' => 'Send replies  from people not subscribed to'),
1030         'microid' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 1, 'description' => 'Publish a MicroID'),
1031         'updatefrompresence' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 0, 'description' => 'Send replies from people not subscribed to.'),
1032         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
1033         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
1034     ),
1035     'primary key' => array('user_id', 'transport'),
1036     'unique keys' => array(
1037         'transport_screenname_key' => array('transport', 'screenname'),
1038     ),
1039     'foreign keys' => array(
1040         'user_im_prefs_user_id_fkey' => array('user', array('user_id' => 'id')),
1041     ),
1042 );
1043
1044 $schema['conversation'] = array(
1045     'fields' => array(
1046         'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
1047         'uri' => array('type' => 'varchar', 'length' => 225, 'description' => 'URI of the conversation'),
1048         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
1049         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
1050     ),
1051     'primary key' => array('id'),
1052     'unique keys' => array(
1053         'conversation_uri_key' => array('uri'),
1054     ),
1055 );
1056
1057 $schema['local_group'] = array(
1058     'description' => 'Record for a user group on the local site, with some additional info not in user_group',
1059     'fields' => array(
1060         'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group represented'),
1061         'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'group represented'),
1062
1063         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
1064         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
1065     ),
1066     'primary key' => array('group_id'),
1067     'foreign keys' => array(
1068         'local_group_group_id_fkey' => array('user_group', array('group_id' => 'id')),
1069     ),
1070     'unique keys' => array(
1071         'local_group_nickname_key' => array('nickname'),
1072     ),
1073 );
1074
1075 $schema['user_urlshortener_prefs'] = array(
1076     'fields' => array(
1077         'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user'),
1078         'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'internal', 'description' => 'service to use for auto-shortening URLs'),
1079         'maxurllength' => array('type' => 'int', 'not null' => true, 'description' => 'urls greater than this length will be shortened, 0 = always, null = never'),
1080         'maxnoticelength' => array('type' => 'int', 'not null' => true, 'description' => 'notices with content greater than this value will have all urls shortened, 0 = always, null = never'),
1081         
1082         'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
1083         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
1084     ),
1085     'primary key' => array('user_id'),
1086     'foreign keys' => array(
1087         'user_urlshortener_prefs_user_id_fkey' => array('user', array('user_id' => 'id')),
1088     ),
1089 );
1090
1091 $schema['schema_version'] = array(
1092     '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.',
1093     'fields' => array(
1094         'table_name' => array('type' => 'varchar', 'length' => '64', 'not null' => true, 'description' => 'Table name'),
1095         'checksum' => array('type' => 'varchar', 'length' => '64', 'not null' => true, 'description' => 'Checksum of schema array; a mismatch indicates we should check the table more thoroughly.'),
1096         'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
1097     ),
1098     'primary key' => array('table_name'),
1099 );
1100
1101 $schema['group_join_queue'] = Group_join_queue::schemaDef();