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