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