]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '1.0.x' into schema-x
authorBrion Vibber <brion@pobox.com>
Thu, 7 Oct 2010 00:16:13 +0000 (17:16 -0700)
committerBrion Vibber <brion@pobox.com>
Thu, 7 Oct 2010 00:16:13 +0000 (17:16 -0700)
Conflicts:
plugins/OStatus/classes/Ostatus_profile.php

classes/Managed_DataObject.php [new file with mode: 0644]
db/core.php [new file with mode: 0644]
lib/mysqlschema.php
lib/pgsqlschema.php
lib/schema.php
plugins/CacheLog/locale/nb/LC_MESSAGES/CacheLog.po [deleted file]
plugins/OStatus/classes/Ostatus_profile.php

diff --git a/classes/Managed_DataObject.php b/classes/Managed_DataObject.php
new file mode 100644 (file)
index 0000000..162c3c8
--- /dev/null
@@ -0,0 +1,153 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * Wrapper for Memcached_DataObject which knows its own schema definition.
+ * Builds its own damn settings from a schema definition.
+ *
+ * @author Brion Vibber <brion@status.net>
+ */
+abstract class Managed_DataObject extends Memcached_DataObject
+{
+    /**
+     * The One True Thingy that must be defined and declared.
+     */
+    public static abstract function schemaDef();
+
+    /**
+     * get/set an associative array of table columns
+     *
+     * @access public
+     * @return array (associative)
+     */
+    function table()
+    {
+        $table = self::schemaDef();
+        return array_map(array($this, 'columnBitmap'), $table['fields']);
+    }
+
+    /**
+     * get/set an  array of table primary keys
+     *
+     * Key info is pulled from the table definition array.
+     * 
+     * @access private
+     * @return array
+     */
+    function keys()
+    {
+        return array_keys($this->keyTypes());
+    }
+
+    /**
+     * Get a sequence key
+     *
+     * Returns the first serial column defined in the table, if any.
+     *
+     * @access private
+     * @return array (column,use_native,sequence_name)
+     */
+
+    function sequenceKey()
+    {
+        $table = self::schemaDef();
+        foreach ($table['fields'] as $name => $column) {
+            if ($column['type'] == 'serial') {
+                // We have a serial/autoincrement column.
+                // Declare it to be a native sequence!
+                return array($name, true, false);
+            }
+        }
+
+        // No sequence key on this table.
+        return array(false, false, false);
+    }
+
+    /**
+     * Return key definitions for DB_DataObject and Memcache_DataObject.
+     *
+     * DB_DataObject needs to know about keys that the table has; this function
+     * defines them.
+     *
+     * @return array key definitions
+     */
+
+    function keyTypes()
+    {
+        $keys = array();
+        $table = self::schemaDef();
+
+        if (!empty($table['unique keys'])) {
+            foreach ($table['unique keys'] as $idx => $fields) {
+                foreach ($fields as $name) {
+                    $keys[$name] = 'U';
+                }
+            }
+        }
+
+        if (!empty($table['primary key'])) {
+            foreach ($table['primary key'] as $name) {
+                $keys[$name] = 'K';
+            }
+        }
+        return $keys;
+    }
+
+    /**
+     * Build the appropriate DB_DataObject bitfield map for this field.
+     *
+     * @param array $column
+     * @return int
+     */
+    function columnBitmap($column)
+    {
+        $type = $column['type'];
+
+        // For quoting style...
+        $intTypes = array('int',
+                          'integer',
+                          'float',
+                          'serial',
+                          'numeric');
+        if (in_array($type, $intTypes)) {
+            $style = DB_DATAOBJECT_INT;
+        } else {
+            $style = DB_DATAOBJECT_STR;
+        }
+
+        // Data type formatting style...
+        $formatStyles = array('blob' => DB_DATAOBJECT_BLOB,
+                              'text' => DB_DATAOBJECT_TXT,
+                              'date' => DB_DATAOBJECT_DATE,
+                              'time' => DB_DATAOBJECT_TIME,
+                              'datetime' => DB_DATAOBJECT_DATE | DB_DATAOBJECT_TIME,
+                              'timestamp' => DB_DATAOBJECT_MYSQLTIMESTAMP);
+
+        if (isset($formatStyles[$type])) {
+            $style |= $formatStyles[$type];
+        }
+
+        // Nullable?
+        if (!empty($column['not null'])) {
+            $style |= DB_DATAOBJECT_NOTNULL;
+        }
+
+        return $style;
+    }
+}
\ No newline at end of file
diff --git a/db/core.php b/db/core.php
new file mode 100644 (file)
index 0000000..04c53a5
--- /dev/null
@@ -0,0 +1,1003 @@
+<?php
+
+/**
+
+Some notes...
+
+drupal docs don't list a bool type, but it might be nice to use rather than 'tinyint'
+note however that we use bitfields and things as well in tinyints
+
+decimal <-> numeric
+
+timestamps... how to specify?
+fulltext indexes?
+got one or two things wanting a custom charset setting on a field?
+
+foreign keys are kinda funky...
+    those specified in inline syntax (as all in the original .sql) are NEVER ENFORCED on mysql
+    those made with an explicit 'foreign key' WITHIN INNODB and IF there's a proper index, do get enforced
+    double-check what we've been doing on postgres?
+
+*/
+
+$schema['profile'] = array(
+    'description' => 'local and remote users have profiles',
+    'fields' => array(
+        'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
+        'nickname' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'nickname or username'),
+        'fullname' => array('type' => 'varchar', 'length' => 255, 'description' => 'display name'),
+        'profileurl' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL, cached so we dont regenerate'),
+        'homepage' => array('type' => 'varchar', 'length' => 255, 'description' => 'identifying URL'),
+        'bio' => array('type' => 'text', 'description' => 'descriptive biography'),
+        'location' => array('type' => 'varchar', 'length' => 255, 'description' => 'physical location'),
+        'lat' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'),
+        'lon' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'),
+        'location_id' => array('type' => 'int', 'description' => 'location id if possible'),
+        'location_ns' => array('type' => 'int', 'description' => 'namespace for location'),
+
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('id'),
+    'indexes' => array(
+        'profile_nickname_idx' => array('nickname'),
+        'FULLTEXT' => array('nickname', 'fullname', 'location', 'bio', 'homepage') // ??
+    ),
+// Any way to specify that this table needs to be myisam if using the fulltext?
+);
+
+$schema['avatar'] = array(
+    'fields' => array(
+        'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
+        'original' => array('type' => 'boolean', 'default' => false, 'description' => 'uploaded by user or generated?'),
+        'width' => array('type' => 'int', 'not null' => true, 'description' => 'image width'),
+        'height' => array('type' => 'int', 'not null' => true, 'description' => 'image height'),
+        'mediatype' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'file type'),
+        'filename' => array('type' => 'varchar', 'length' => 255, 'description' => 'local filename, if local'),
+        'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'avatar location'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('profile_id', 'width', 'height'),
+    'unique keys' => array(
+        'avatar_url_idx' => array('url'),
+    ),
+    'foreign keys' => array(
+        'profile_id' => array('profile' => 'id'),
+    ),
+    'indexes' => array(
+        'avatar_profile_id_idx' => array('profile_id'),
+    ),
+);
+
+$schema['sms_carrier'] = array(
+    'fields' => array(
+        'id' => array('type' => 'int', 'description' => 'primary key for SMS carrier'),
+        'name' => array('type' => 'varchar', 'length' => 64, 'description' => 'name of the carrier'),
+        'email_pattern' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'sprintf pattern for making an email address from a phone number'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('id'),
+    'unique keys' => array(
+        'sms_carrier_name_idx' => array('name'),
+    ),
+);
+
+$schema['user'] = array(
+    'description' => 'local users',
+    'fields' => array(
+        'id' => array('type' => 'int', 'description' => 'foreign key to profile table'),
+        'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'nickname or username, duped in profile'),
+        'password' => array('type' => 'varchar', 'length' => 255, 'description' => 'salted password, can be null for OpenID users'),
+        'email' => array('type' => 'varchar', 'length' => 255, 'description' => 'email address for password recovery etc.'),
+        'incomingemail' => array('type' => 'varchar', 'length' => 255, 'description' => 'email address for post-by-email'),
+        'emailnotifysub' => array('type' => 'bool', 'default' => 1, 'description' => 'Notify by email of subscriptions'),
+        'emailnotifyfav' => array('type' => 'bool', 'default' => 1, 'description' => 'Notify by email of favorites'),
+        'emailnotifynudge' => array('type' => 'bool', 'default' => 1, 'description' => 'Notify by email of nudges'),
+        'emailnotifymsg' => array('type' => 'bool', 'default' => 1, 'description' => 'Notify by email of direct messages'),
+        'emailnotifyattn' => array('type' => 'bool', 'default' => 1, 'description' => 'Notify by email of @-replies'),
+        'emailmicroid' => array('type' => 'bool', 'default' => 1, 'description' => 'whether to publish email microid'),
+        'language' => array('type' => 'varchar', 'length' => 50, 'description' => 'preferred language'),
+        'timezone' => array('type' => 'varchar', 'length' => 50, 'description' => 'timezone'),
+        'emailpost' => array('type' => 'bool', 'default' => 1, 'description' => 'Post by email'),
+        'sms' => array('type' => 'varchar', 'length' => 64, 'description' => 'sms phone number'),
+        'carrier' => array('type' => 'int', 'description' => 'foreign key to sms_carrier'),
+        'smsnotify' => array('type' => 'bool', 'default' => 0, 'description' => 'whether to send notices to SMS'),
+        'smsreplies' => array('type' => 'bool', 'default' => 0, 'description' => 'whether to send notices to SMS on replies'),
+        'smsemail' => array('type' => 'varchar', 'length' => 255, 'description' => 'built from sms and carrier'),
+        'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier, usually a tag URI'),
+        'autosubscribe' => array('type' => 'bool', 'default' => 0, 'description' => 'automatically subscribe to users who subscribe to us'),
+        'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'ur1.ca', 'description' => 'service to use for auto-shortening URLs'),
+        'inboxed' => array('type' => 'bool', 'default' => 0, 'description' => 'has an inbox been created for this user?'),
+        'design_id' => array('type' => 'int', 'description' => 'id of a design'),
+        'viewdesigns' => array('type' => 'bool', 'default' => 1, 'description' => 'whether to view user-provided designs'),
+
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('id'),
+    'unique keys' => array(
+        'user_name_idx' => array('name'),
+        'user_email_idx' => array('email'),
+        'user_incomingemail_idx' => array('incomingemail'),
+        'user_sms_idx' => array('sms'),
+        'user_uri_idx' => array('uri'),
+    ),
+    'foreign keys' => array(
+        'id' => array('profile' => 'id'),
+        'carrier' => array('sms_carrier' => 'id'),
+        'design_id' => array('desgin' => 'id'),
+    ),
+    'indexes' => array(
+        'user_smsemail_idx' => array('smsemail'),
+    ),
+);
+
+$schema['remote_profile'] = array(
+    'description' => 'remote people (OMB)',
+    'fields' => array(
+        'id' => array('type' => 'int', 'description' => 'foreign key to profile table'),
+        'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier, usually a tag URI'),
+        'postnoticeurl' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL we use for posting notices'),
+        'updateprofileurl' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL we use for updates to this profile'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('id'),
+    'unique keys' => array(
+        'remote_profile_uri_idx' => array('uri'),
+    ),
+    'foreign keys' => array(
+        'id' => array('profile' => 'id'),
+    ),
+);
+
+$schema['subscription'] = array(
+    'fields' => array(
+        'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'profile listening'),
+        'subscribed' => array('type' => 'int', 'not null' => true, 'description' => 'profile being listened to'),
+        'jabber' => array('type' => 'bool', 'default' => 1, 'description' => 'deliver jabber messages'),
+        'sms' => array('type' => 'bool', 'default' => 1, 'description' => 'deliver sms messages'),
+        'token' => array('type' => 'varchar', 'length' => 255, 'description' => 'authorization token'),
+        'secret' => array('type' => 'varchar', 'length' => 255, 'description' => 'token secret'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('subscriber', 'subscribed'),
+    'indexes' => array(
+        'subscription_subscriber_idx' => array('subscriber', 'created'),
+        'subscription_subscribed_idx' => array('subscribed', 'created'),
+        'subscription_token_idx' => array('token'),
+    ),
+);
+
+$schema['notice'] = array(
+    'fields' => array(
+        'id' => array('type' => 'serial', 'description' => 'unique identifier'),
+        'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'who made the update'),
+        'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier, usually a tag URI'),
+        'content' => array('type' => 'text', 'description' => 'update content'),
+        'rendered' => array('type' => 'text', 'description' => 'HTML version of the content'),
+        'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of any attachment (image, video, bookmark, whatever)'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+        'reply_to' => array('type' => 'int', 'description' => 'notice replied to (usually a guess)'),
+        'is_local' => array('type' => 'bool', 'default' => 0, 'description' => 'notice was generated by a user'),
+        'source' => array('type' => 'varchar', 'length' => 32, 'description' => 'source of comment, like "web", "im", or "clientname"'),
+        'conversation' => array('type' => 'int', 'description' => 'id of root notice in this conversation'),
+        'lat' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'),
+        'lon' => array('type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'),
+        'location_id' => array('type' => 'int', 'description' => 'location id if possible'),
+        'location_ns' => array('type' => 'int', 'description' => 'namespace for location'),
+        'repeat_of' => array('type' => 'int', 'description' => 'notice this is a repeat of'),
+    ),
+    'primary key' => array('id'),
+    'unique keys' => array(
+        'notice_uri_idx' => array('uri'),
+    ),
+    'foreign keys' => array(
+        'profile_id' => array('profile' => 'id'),
+        'reply_to' => array('notice', 'id'),
+        'conversation' => array('conversation', 'id'), # note... used to refer to notice.id
+        'repeat_of' => array('notice', 'id'), # @fixme: what about repeats of deleted notices?
+    ),
+    'indexes' => array(
+        'notice_profile_id_idx' => array('profile_id,created,id'),
+        'notice_conversation_idx' => array('conversation'),
+        'notice_created_idx' => array('created'),
+        'notice_replyto_idx' => array('reply_to'),
+        'notice_repeatof_idx' => array('repeat_of'),
+        'FULLTEXT' => array('content'),
+    ),
+);
+
+$schema['notice_source'] = array(
+    'fields' => array(
+        'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'source code'),
+        'name' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'name of the source'),
+        'url' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'url to link to'),
+        'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('code'),
+);
+
+$schema['reply'] = array(
+    'fields' => array(
+        'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice that is the reply'),
+        'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile replied to'),
+        'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+        'replied_id' => array('type' => 'int', 'description' => 'notice replied to (not used, see notice.reply_to)'),
+    ),
+    'primary key' => array('notice_id', 'profile_id'),
+    'foreign keys' => array(
+        'notice_id' => array('notice' => 'id'),
+        'profile_id' => array('profile' => 'id'),
+    ),
+    'indexes' => array(
+        'reply_notice_id_idx' => array('notice_id'),
+        'reply_profile_id_idx' => array('profile_id'),
+        'reply_replied_id_idx' => array('replied_id'),
+    ),
+);
+
+$schema['fave'] = array(
+    'fields' => array(
+        'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice that is the favorite'),
+        'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who likes this notice'),
+        'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('notice_id', 'user_id'),
+    'foreign keys' => array(
+        'notice_id' => array('notice', 'id'),
+        'user_id' => array('profile', 'id'), // note: formerly referenced notice.id, but we can now record remote users' favorites
+    ),
+    'indexes' => array(
+        'fave_notice_id_idx' => array('notice_id'),
+        'fave_user_id_idx' => array('user_id', 'modified'),
+        'fave_modified_idx' => array('modified'),
+    ),
+);
+
+/* tables for OAuth */
+
+$schema['consumer'] = array(
+    'description' => 'OAuth consumer record',
+    'fields' => array(
+        'consumer_key' => array('type' => 'varchar', 'length' => 255, 'description' => 'unique identifier, root URL'),
+        'consumer_secret' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'secret value'),
+        'seed' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'seed for new tokens by this consumer'),
+
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('consumer_key'),
+);
+
+$schema['token'] = array(
+    'description' => 'OAuth token record',
+    'fields' => array(
+        'consumer_key' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'unique identifier, root URL'),
+        'tok' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'identifying value'),
+        'secret' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'secret value'),
+        'type' => array('type' => 'bool', 'not null' => true, 'default' => 0, 'description' => 'request or access'),
+        'state' => array('type' => 'bool', 'default' => 0, 'description' => 'for requests, 0 = initial, 1 = authorized, 2 = used'),
+        'verifier' => array('type' => 'varchar', 'length' => 255, 'description' => 'verifier string for OAuth 1.0a'),
+        'verified_callback' => array('type' => 'varchar', 'length' => 255, 'description' => 'verified callback URL for OAuth 1.0a'),
+
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('consumer_key', 'tok'),
+    'foreign keys' => array(
+        'consumer_key' => array('consumer' => 'consumer_key'),
+    ),
+);
+
+$schema['nonce'] = array(
+    'description' => 'OAuth nonce record',
+    'fields' => array(
+        'consumer_key' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'unique identifier, root URL'),
+        'tok' => array('type' => 'char', 'length' => 32, 'description' => 'buggy old value, ignored'),
+        'nonce' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'nonce'),
+        'ts' => array('type' => 'datetime', 'not null' => true, 'description' => 'timestamp sent'),
+
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('consumer_key', 'ts', 'nonce'),
+);
+
+$schema['oauth_application'] = array(
+    'description' => 'OAuth application registration record',
+    'fields' => array(
+        'id' => array('type' => 'serial', 'description' => 'unique identifier'),
+        'owner' => array('type' => 'int', 'not null' => true, 'description' => 'owner of the application'),
+        'consumer_key' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'application consumer key'),
+        'name' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'name of the application'),
+        'description' => array('type' => 'varchar', 'length' => 255, 'description' => 'description of the application'),
+        'icon' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'application icon'),
+        'source_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'application homepage - used for source link'),
+        'organization' => array('type' => 'varchar', 'length' => 255, 'description' => 'name of the organization running the application'),
+        'homepage' => array('type' => 'varchar', 'length' => 255, 'description' => 'homepage for the organization'),
+        'callback_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'url to redirect to after authentication'),
+        'type' => array('type' => 'bool', 'default' => 0, 'description' => 'type of app, 1 = browser, 2 = desktop'),
+        'access_type' => array('type' => 'bool', 'default' => 0, 'description' => 'default access type, bit 1 = read, bit 2 = write'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('id'),
+    'unique keys' => array(
+        'oauth_application_name_idx' => array('name'), // in the long run, we should perhaps not force these unique, and use another source id
+    ),
+    'foreign keys' => array(
+        'owner' => array('profile' => 'id'), // Are remote users allowed to create oauth application records?
+        'consumer_key' => array('consumer' => 'consumer_key'),
+    ),
+);
+
+$schema['oauth_application_user'] = array(
+    'fields' => array(
+        'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'user of the application'),
+        'application_id' => array('type' => 'int', 'not null' => true, 'description' => 'id of the application'),
+        'access_type' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'access type, bit 1 = read, bit 2 = write'),
+        'token' => array('type' => 'varchar', 'length' => 255, 'description' => 'request or access token'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('profile_id', 'application_id'),
+    'foreign keys' => array(
+        'profile_id' => array('profile' => 'id'),
+        'application_id' => array('oauth_application' => 'id'),
+    ),
+);
+
+/* These are used by JanRain OpenID library */
+
+$schema['oid_associations'] = array(
+    'fields' => array(
+        'server_url' => array('type' => 'blob'),
+        'handle' => array('type' => 'varchar', 'length' => 255), // character set latin1,
+        'secret' => array('type' => 'blob'),
+        'issued' => array('type' => 'int'),
+        'lifetime' => array('type' => 'int'),
+        'assoc_type' => array('type' => 'varchar', 'length' => 64),
+    ),
+    'primary key' => array(array('server_url', 255), 'handle'),
+);
+
+$schema['oid_nonces'] = array(
+    'fields' => array(
+        'server_url' => array('type' => 'varchar', 'length' => 2047),
+        'timestamp' => array('type' => 'int'),
+        'salt' => array('type' => 'char', 'length' => 40),
+    ),
+    'unique keys' => array(
+        'oid_nonces_server_url_type_idx' => array(array('server_url', 255), 'timestamp', 'salt'),
+    ),
+);
+
+$schema['confirm_address'] = array(
+    'fields' => array(
+        'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'good random code'),
+        'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who requested confirmation'),
+        'address' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'address (email, xmpp, SMS, etc.)'),
+        'address_extra' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'carrier ID, for SMS'),
+        'address_type' => array('type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'),
+        'claimed' => array('type' => 'datetime', 'description' => 'date this was claimed for queueing'),
+        'sent' => array('type' => 'datetime', 'description' => 'date this was sent for queueing'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('code'),
+    'foreign keys' => array(
+        'user_id' => array('user' => 'id'),
+    ),
+);
+
+$schema['remember_me'] = array(
+    'fields' => array(
+        'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'good random code'),
+        'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who is logged in'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('code'),
+    'foreign keys' => array(
+        'user_id' => array('user' => 'id'),
+    ),
+);
+
+$schema['queue_item'] = array(
+    'fields' => array(
+        'id' => array('type' => 'serial', 'description' => 'unique identifier'),
+        'frame' => array('type' => 'blob', 'not null' => true, 'description' => 'data: object reference or opaque string'),
+        '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.
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'claimed' => array('type' => 'datetime', 'description' => 'date this item was claimed'),
+    ),
+    'primary key' => array('id'),
+    'indexes' => array(
+        'queue_item_created_idx' => array('created'),
+    ),
+);
+
+$schema['notice_tag'] = array(
+    'description' => 'Hash tags',
+    'fields' => array(
+        'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this notice'),
+        'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice tagged'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+    ),
+    'primary key' => array('tag', 'notice_id'),
+    'foreign keys' => array(
+        'notice_id' => array('notice' => 'id'),
+    ),
+    'indexes' => array(
+        'notice_tag_created_idx' => array('created'),
+        'notice_tag_notice_id_idx' => array('notice_id'),
+    ),
+);
+
+/* Synching with foreign services */
+
+$schema['foreign_service'] = array(
+    'fields' => array(
+        'id' => array('type' => 'int', 'not null' => true, 'description' => 'numeric key for service'),
+        'name' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'name of the service'),
+        'description' => array('type' => 'varchar', 'length' => 255, 'description' => 'description'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('id'),
+    'unique keys' => array(
+        'foreign_service_name_idx' => array('name'),
+    ),
+);
+
+$schema['foreign_user'] = array(
+    'fields' => array(
+        'id' => array('type' => 'bigint', 'not null' => true, 'description' => 'unique numeric key on foreign service'),
+        'service' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to service'),
+        'uri' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'identifying URI'),
+        'nickname' => array('type' => 'varchar', 'length' => 255, 'description' => 'nickname on foreign service'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('id', 'service'),
+    'foreign keys' => array(
+        'service' => array('foreign_service' => 'id'),
+    ),
+    'unique keys' => array(
+        'foreign_user_uri_idx' => array('uri'),
+    ),
+);
+
+$schema['foreign_link'] = array(
+    'fields' => array(
+        'user_id' => array('type' => 'int', 'description' => 'link to user on this system, if exists'),
+        'foreign_id' => array('type' => 'int', 'size' => 'big', 'unsigned' => true, 'description' => 'link to user on foreign service, if exists'),
+        'service' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to service'),
+        'credentials' => array('type' => 'varchar', 'length' => 255, 'description' => 'authc credentials, typically a password'),
+        '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'),
+        'friendsync' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 2, 'description' => 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'),
+        'profilesync' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 1, 'description' => 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'),
+        'last_noticesync' => array('type' => 'datetime', 'description' => 'last time notices were imported'),
+        'last_friendsync' => array('type' => 'datetime', 'description' => 'last time friends were imported'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('user_id', 'foreign_id', 'service'),
+    'foreign keys' => array(
+        'user_id' => array('user' => 'id'),
+        'foreign_id' => array('foreign_user' => 'id'),
+        'service' => array('foreign_service' => 'id'),
+    ),
+    'indexes' => array(
+        'foreign_user_user_id_idx' => array('user_id'),
+    ),
+);
+
+$schema['foreign_subscription'] = array(
+    'fields' => array(
+        'service' => array('type' => 'int', 'not null' => true, 'description' => 'service where relationship happens'),
+        'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'subscriber on foreign service'),
+        'subscribed' => array('type' => 'int', 'not null' => true, 'description' => 'subscribed user'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+    ),
+    'primary key' => array('service', 'subscriber', 'subscribed'),
+    'foreign keys' => array(
+        'service' => array('foreign_service' => 'id'),
+        'subscriber' => array('foreign_user' => 'id'),
+        'subscribed' => array('foreign_user' => 'id'),
+    ),
+    'indexes' => array(
+        'foreign_subscription_subscriber_idx' => array('subscriber'),
+        'foreign_subscription_subscribed_idx' => array('subscribed'),
+    ),
+);
+
+$schema['invitation'] = array(
+    'fields' => array(
+        'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'random code for an invitation'),
+        'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'who sent the invitation'),
+        'address' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'invitation sent to'),
+        'address_type' => array('type' => 'varchar', 'length' => 8, 'not null' => true, 'description' => 'address type ("email", "xmpp", "sms")'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+    ),
+    'primary key' => array('code'),
+    'foreign keys' => array(
+        'user_id' => array('user' => 'id'),
+    ),
+    'indexes' => array(
+        'invitation_address_idx' => array('address', 'address_type'),
+        'invitation_user_id_idx' => array('user_id'),
+    ),
+);
+
+$schema['message'] = array(
+    'fields' => array(
+        'id' => array('type' => 'serial', 'description' => 'unique identifier'),
+        'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier'),
+        'from_profile' => array('type' => 'int', 'not null' => true, 'description' => 'who the message is from'),
+        'to_profile' => array('type' => 'int', 'not null' => true, 'description' => 'who the message is to'),
+        'content' => array('type' => 'text', 'description' => 'message content'),
+        'rendered' => array('type' => 'text', 'description' => 'HTML version of the content'),
+        'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of any attachment (image, video, bookmark, whatever)'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+        'source' => array('type' => 'varchar', 'length' => 32, 'description' => 'source of comment, like "web", "im", or "clientname"'),
+    ),
+    'primary key' => array('id'),
+    'unique key' => array(
+        'message_uri_idx' => array('uri'),
+    ),
+    'foreign keys' => array(
+        'from_profile' => array('profile' => 'id'),
+        'to_profile' => array('profile' => 'id'),
+    ),
+    'indexes' => array(
+        // @fixme these are really terrible indexes, since you can only sort on one of them at a time.
+        // looks like we really need a (to_profile, created) for inbox and a (from_profile, created) for outbox
+        'message_from_idx' => array('from_profile'),
+        'message_to_idx' => array('to_profile'),
+        'message_created_idx' => array('created'),
+    ),
+);
+
+$schema['notice_inbox'] = array(
+    'description' => 'Obsolete; old entries here are converted to packed entries in the inbox table since 0.9',
+    'fields' => array(
+        'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user receiving the message'),
+        'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice received'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice was created'),
+        'source' => array('type' => 'bool', 'default' => 1, 'description' => 'reason it is in the inbox, 1=subscription'),
+    ),
+    'primary key' => array('user_id', 'notice_id'),
+    'foreign keys' => array(
+        'user_id' => array('user' => 'id'),
+        'notice_id' => array('notice' => 'id'),
+    ),
+    'indexes' => array(
+        'notice_inbox_notice_id_idx' => array('notice_id'),
+    ),
+);
+
+$schema['profile_tag'] = array(
+    'fields' => array(
+        'tagger' => array('type' => 'int', 'not null' => true, 'description' => 'user making the tag'),
+        'tagged' => array('type' => 'int', 'not null' => true, 'description' => 'profile tagged'),
+        'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this notice'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date the tag was added'),
+    ),
+    'primary key' => array('tagger', 'tagged', 'tag'),
+    'foreign keys' => array(
+        'tagger' => array('user' => 'id'),
+        'tagged' => array('profile' => 'id'),
+    ),
+    'indexes' => array(
+        'profile_tag_modified_idx' => array('modified'),
+        'profile_tag_tagger_tag_idx' => array('tagger', 'tag'),
+        'profile_tag_tagged_idx' => array('tagged'),
+    ),
+);
+
+$schema['profile_block'] = array(
+    'fields' => array(
+        'blocker' => array('type' => 'int', 'not null' => true, 'description' => 'user making the block'),
+        'blocked' => array('type' => 'int', 'not null' => true, 'description' => 'profile that is blocked'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date of blocking'),
+    ),
+    'foreign keys' => array(
+        'blocker' => array('user' => 'id'),
+        'blocked' => array('profile' => 'id'),
+    ),
+    'primary key' => array('blocker', 'blocked'),
+);
+
+$schema['user_group'] = array(
+    'fields' => array(
+        'id' => array('type' => 'serial', 'description' => 'unique identifier'),
+
+        'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'nickname for addressing'),
+        'fullname' => array('type' => 'varchar', 'length' => 255, 'description' => 'display name'),
+        'homepage' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL, cached so we dont regenerate'),
+        'description' => array('type' => 'text', 'description' => 'group description'),
+        'location' => array('type' => 'varchar', 'length' => 255, 'description' => 'related physical location, if any'),
+
+        'original_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'original size logo'),
+        'homepage_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'homepage (profile) size logo'),
+        'stream_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'stream-sized logo'),
+        'mini_logo' => array('type' => 'varchar', 'length' => 255, 'description' => 'mini logo'),
+        'design_id' => array('type' => 'int', 'description' => 'id of a design'),
+
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+
+        'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universal identifier'),
+        'mainpage' => array('type' => 'varchar', 'length' => 255, 'description' => 'page for group info to link to'),
+    ),
+    'primary key' => array('id'),
+    'unique key' => array(
+        'user_uri_idx' => array('uri'),
+    ),
+    'foreign keys' => array(
+        'design_id' => array('design' => 'id'),
+    ),
+    'indexes' => array(
+        'user_group_nickname_idx' => array('nickname'),
+    ),
+);
+
+$schema['group_member'] = array(
+    'fields' => array(
+        'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
+        'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
+        'is_admin' => array('type' => 'boolean', 'default' => false, 'description' => 'is this user an admin?'),
+
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('group_id', 'profile_id'),
+    'foreign keys' => array(
+        'group_id' => array('user_group' => 'id'),
+        'profile_id' => array('profile' => 'id'),
+    ),
+    'indexes' => array(
+        // @fixme probably we want a (profile_id, created) index here?
+        'group_member_profile_id_idx' => array('profile_id'),
+        'group_member_created_idx' => array('created'),
+    ),
+);
+
+$schema['related_group'] = array(
+    // @fixme description for related_group?
+    'fields' => array(
+        'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
+        'related_group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
+
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+    ),
+    'primary key' => array('group_id', 'related_group_id'),
+    'foreign keys' => array(
+        'group_id' => array('user_group' => 'id'),
+        'related_group_id' => array('user_group' => 'id'),
+    ),
+);
+
+$schema['group_inbox'] = array(
+    'description' => 'Many-many table listing notices posted to a given group, or which groups a given notice was posted to.',
+    'fields' => array(
+        'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group receiving the message'),
+        'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice received'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice was created'),
+    ),
+    'primary key' => array('group_id', 'notice_id'),
+    'foreign keys' => array(
+        'group_id' => array('user_group' => 'id'),
+        'notice_id' => array('notice' => 'id'),
+    ),
+    'indexes' => array(
+        'group_inbox_created_idx' => array('created'),
+        'group_inbox_notice_id_idx' => array('notice_id'),
+    ),
+);
+
+$schema['file'] = array(
+    'fields' => array(
+        'id' => array('type' => 'serial'),
+        'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'destination URL after following redirections'),
+        'mimetype' => array('type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'),
+        'size' => array('type' => 'int', 'description' => 'size of resource when available'),
+        'title' => array('type' => 'varchar', 'length' => 255, 'description' => 'title of resource when available'),
+        'date' => array('type' => 'int', 'description' => 'date of resource according to http query'),
+        'protected' => array('type' => 'int', 'description' => 'true when URL is private (needs login)'),
+        'filename' => array('type' => 'varchar', 'length' => 255, 'description' => 'if a local file, name of the file'),
+
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('id'),
+    'unique keys' => array(
+        'file_url_idx' => array('url'),
+    ),
+);
+
+$schema['file_oembed'] = array(
+    'fields' => array(
+        'file_id' => array('type' => 'int', 'description' => 'oEmbed for that URL/file'),
+        'version' => array('type' => 'varchar', 'length' => 20, 'description' => 'oEmbed spec. version'),
+        'type' => array('type' => 'varchar', 'length' => 20, 'description' => 'oEmbed type: photo, video, link, rich'),
+        'mimetype' => array('type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'),
+        'provider' => array('type' => 'varchar', 'length' => 50, 'description' => 'name of this oEmbed provider'),
+        'provider_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of this oEmbed provider'),
+        'width' => array('type' => 'int', 'description' => 'width of oEmbed resource when available'),
+        'height' => array('type' => 'int', 'description' => 'height of oEmbed resource when available'),
+        'html' => array('type' => 'text', 'description' => 'html representation of this oEmbed resource when applicable'),
+        'title' => array('type' => 'varchar', 'length' => 255, 'description' => 'title of oEmbed resource when available'),
+        'author_name' => array('type' => 'varchar', 'length' => 50, 'description' => 'author name for this oEmbed resource'),
+        'author_url' => array('type' => 'varchar', 'length' => 255, 'description' => 'author URL for this oEmbed resource'),
+        'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL for this oEmbed resource when applicable (photo, link)'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('file_id'),
+    'foreign keys' => array(
+         'file_id' => array('file' => 'id'),
+    ),
+);
+
+$schema['file_redirection'] = array(
+    'fields' => array(
+        'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'short URL (or any other kind of redirect) for file (id)'),
+        'file_id' => array('type' => 'int', 'description' => 'short URL for what URL/file'),
+        'redirections' => array('type' => 'int', 'description' => 'redirect count'),
+        'httpcode' => array('type' => 'int', 'description' => 'HTTP status code (20x, 30x, etc.)'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('url'),
+    'foreign keys' => array(
+         'file_id' => array('file' => 'id'),
+    ),
+);
+
+$schema['file_thumbnail'] = array(
+    'fields' => array(
+        'file_id' => array('type' => 'int',  'description' => 'thumbnail for what URL/file'),
+        'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of thumbnail'),
+        'width' => array('type' => 'int', 'description' => 'width of thumbnail'),
+        'height' => array('type' => 'int', 'description' => 'height of thumbnail'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('file_id'),
+    'foreign keys' => array(
+        'file_id' => array('file' => 'id'),
+    ),
+    'unique keys' => array(
+        'file_thumbnail_url_idx' => array('url'),
+    ),
+);
+
+$schema['file_to_post'] = array(
+    'fields' => array(
+        'file_id' => array('type' => 'int', 'description' => 'id of URL/file'),
+        'post_id' => array('type' => 'int', 'description' => 'id of the notice it belongs to'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('file_id', 'post_id'),
+    'foreign keys' => array(
+        'file_id' => array('file' => 'id'),
+        'post_id' => array('notice' => 'id'),
+    ),
+    'indexes' => array(
+        'post_id_idx' => array('post_id'),
+    ),
+);
+
+$schema['design'] = array(
+    'fields' => array(
+        'id' => array('type' => 'serial', 'description' => 'design ID'),
+        'backgroundcolor' => array('type' => 'int', 'description' => 'main background color'),
+        'contentcolor' => array('type' => 'int', 'description' => 'content area background color'),
+        'sidebarcolor' => array('type' => 'int', 'description' => 'sidebar background color'),
+        'textcolor' => array('type' => 'int', 'description' => 'text color'),
+        'linkcolor' => array('type' => 'int', 'description' => 'link color'),
+        'backgroundimage' => array('type' => 'varchar', 'length' => 255, 'description' => 'background image, if any'),
+        'disposition' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'bit 1 = hide background image, bit 2 = display background image, bit 4 = tile background image'),
+    ),
+    'primary key' => array('id'),
+);
+
+$schema['group_block'] = array(
+    'fields' => array(
+        'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group profile is blocked from'),
+        'blocked' => array('type' => 'int', 'not null' => true, 'description' => 'profile that is blocked'),
+        'blocker' => array('type' => 'int', 'not null' => true, 'description' => 'user making the block'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date of blocking'),
+    ),
+    'primary key' => array('group_id', 'blocked'),
+    'foreign keys' => array(
+        'group_id' => array('user_group' => 'id'),
+        'blocked' => array('profile' => 'id'),
+        'blocker' => array('user' => 'id'),
+    ),
+);
+
+$schema['group_alias'] = array(
+    'fields' => array(
+        'alias' => array('type' => 'varchar', 'length' => 64, 'description' => 'additional nickname for the group'),
+        'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group profile is blocked from'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date alias was created'),
+    ),
+    'primary key' => array('alias'),
+    'foreign keys' => array(
+        'group_id' => array('user_group' => 'id'),
+    ),
+    'indexes' => array(
+        'group_alias_group_id_idx' => array('group_id'),
+    ),
+);
+
+$schema['session'] = array(
+    'fields' => array(
+        'id' => array('type' => 'varchar', 'length' => 32, 'description' => 'session ID'),
+        'session_data' => array('type' => 'text', 'description' => 'session data'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('id'),
+    'indexes' => array(
+        'session_modified_idx' => array('modified'),
+    ),
+);
+
+$schema['deleted_notice'] = array(
+    'fields' => array(
+        'id' => array('type' => 'int', 'description' => 'identity of notice'),
+        'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'author of the notice'),
+        'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universally unique identifier, usually a tag URI'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created'),
+        'deleted' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the notice record was created'),
+    ),
+    'primary key' => array('id'),
+    'unique keys' => array(
+        'deleted_notice_uri_idx' => array('uri'),
+    ),
+    'indexes' => array(
+        'deleted_notice_profile_id_idx' => array('profile_id'),
+    ),
+);
+
+$schema['config'] = array(
+    'fields' => array(
+        'section' => array('type' => 'varchar', 'length' => 32, 'description' => 'configuration section'),
+        'setting' => array('type' => 'varchar', 'length' => 32, 'description' => 'configuration setting'),
+        'value' => array('type' => 'varchar', 'length' => 255, 'description' => 'configuration value'),
+    ),
+    'primary key' => array('section', 'setting'),
+);
+
+$schema['profile_role'] = array(
+    'fields' => array(
+        'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'account having the role'),
+        'role' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'string representing the role'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the role was granted'),
+    ),
+    'primary key' => array('profile_id', 'role'),
+    'foreign keys' => array(
+        'profile_id' => array('profile' => 'id'),
+    ),
+);
+
+$schema['location_namespace'] = array(
+    'fields' => array(
+        'id' => array('type' => 'int', 'description' => 'identity for this namespace'),
+        'description' => array('type' => 'varchar', 'length' => 255, 'description' => 'description of the namespace'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date the record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('id'),
+);
+
+$schema['login_token'] = array(
+    'fields' => array(
+        'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user owning this token'),
+        'token' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'token useable for logging in'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('user_id'),
+    'foreign keys' => array(
+        'user_id' => array('user' => 'id'),
+    ),
+);
+
+$schema['user_location_prefs'] = array(
+    'fields' => array(
+        'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who has the preference'),
+        'share_location' => array('type' => 'bool', 'default' => 1, 'description' => 'Whether to share location data'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array(user_id),
+    'foreign keys' => array(
+        'user_id' => array('user' => 'id'),
+    ),
+);
+
+$schema['inbox'] = array(
+    'fields' => array(
+        'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user receiving the notice'),
+        'notice_ids' => array('type' => 'blob', 'description' => 'packed list of notice ids'),
+    ),
+    'primary key' => array('user_id'),
+    'foreign keys' => array(
+        'user_id' => array('user' => 'id'),
+    ),
+);
+
+// @fixme possibly swap this for a more general prefs table?
+$schema['user_im_prefs'] = array(
+    'fields' => array(
+        'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user'),
+        'screenname' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'screenname on this service'),
+        'transport' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'transport (ex xmpp, aim)'),
+        'notify' => array('type' => 'bool', 'not null' => true, 'default' => 0, 'description' => 'Notify when a new notice is sent'),
+        'replies' => array('type' => 'bool', 'not null' => true, 'default' => 0, 'description' => 'Send replies  from people not subscribed to'),
+        'microid' => array('type' => 'bool', 'not null' => true, 'default' => 1, 'description' => 'Publish a MicroID'),
+        'updatefrompresence' => array('type' => 'bool', 'not null' => true, 'default' => 0, 'description' => 'Send replies from people not subscribed to.'),
+        'created' => array('type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'), // @fixme will that default work?
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('user_id', 'transport'),
+    'unique keys' => array(
+        'transport_screenname_key' => array('transport', 'screenname'),
+    ),
+    'foreign keys' => array(
+        'user_id' => array('user' => 'id'),
+    ),
+);
+
+$schema['conversation'] = array(
+    'fields' => array(
+        'id' => array('type' => 'serial', 'description' => 'unique identifier'),
+        'uri' => array('type' => 'varchar', 'length' => 225, 'description' => 'URI of the conversation'),
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('id'),
+    'unique keys' => array(
+        'conversation_uri_idx' => array('uri'),
+    ),
+);
+
+$schema['local_group'] = array(
+    'description' => 'Record for a user group on the local site, with some additional info not in user_group',
+    'fields' => array(
+        'group_id' => array('type' => 'int', 'description' => 'group represented'),
+        'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'group represented'),
+
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('group_id'),
+    'foreign keys' => array(
+        'group_id' => array('user_group' => 'id'),
+    ),
+    'unique keys' => array(
+        'local_group_nickname_idx' => array('nickname'),
+    ),
+);
+
+$schema['user_urlshortener_prefs'] = array(
+    'fields' => array(
+        'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user'),
+        'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'ur1.ca', 'description' => 'service to use for auto-shortening URLs'),
+        'maxurllength' => array('type' => 'int', 'not null' => true, 'description' => 'urls greater than this length will be shortened, 0 = always, null = never'),
+        'maxnoticelength' => array('type' => 'int', 'not null' => true, 'description' => 'notices with content greater than this value will have all urls shortened, 0 = always, null = never'),
+        
+        'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+        'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+    ),
+    'primary key' => array('user_id'),
+    'foreign keys' => array(
+        'user_id' => array('user' => 'id'),
+    ),
+);
index f9552c1dcdefd5cef37c8d6ad69ab59aaf18cb2a..b84883c034d278310ad81ff2c7fdcd9908c5f48e 100644 (file)
@@ -167,31 +167,6 @@ class MysqlSchema extends Schema
         }
     }
 
-    /**
-     * Gets a ColumnDef object for a single column.
-     *
-     * Throws an exception if the table is not found.
-     *
-     * @param string $table  name of the table
-     * @param string $column name of the column
-     *
-     * @return ColumnDef definition of the column or null
-     *                   if not found.
-     */
-
-    public function getColumnDef($table, $column)
-    {
-        $td = $this->getTableDef($table);
-
-        foreach ($td->columns as $cd) {
-            if ($cd->name == $column) {
-                return $cd;
-            }
-        }
-
-        return null;
-    }
-
     /**
      * Creates a table with the given names and columns.
      *
@@ -289,156 +264,6 @@ class MysqlSchema extends Schema
         return "{$tableName}_{$columnName}_idx";
     }
 
-    /**
-     * Drops a table from the schema
-     *
-     * Throws an exception if the table is not found.
-     *
-     * @param string $name Name of the table to drop
-     *
-     * @return boolean success flag
-     */
-
-    public function dropTable($name)
-    {
-        $res = $this->conn->query("DROP TABLE $name");
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        return true;
-    }
-
-    /**
-     * Adds an index to a table.
-     *
-     * If no name is provided, a name will be made up based
-     * on the table name and column names.
-     *
-     * Throws an exception on database error, esp. if the table
-     * does not exist.
-     *
-     * @param string $table       Name of the table
-     * @param array  $columnNames Name of columns to index
-     * @param string $name        (Optional) name of the index
-     *
-     * @return boolean success flag
-     */
-
-    public function createIndex($table, $columnNames, $name=null)
-    {
-        if (!is_array($columnNames)) {
-            $columnNames = array($columnNames);
-        }
-
-        if (empty($name)) {
-            $name = "{$table}_".implode("_", $columnNames)."_idx";
-        }
-
-        $res = $this->conn->query("ALTER TABLE $table ".
-                                   "ADD INDEX $name (".
-                                   implode(",", $columnNames).")");
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        return true;
-    }
-
-    /**
-     * Drops a named index from a table.
-     *
-     * @param string $table name of the table the index is on.
-     * @param string $name  name of the index
-     *
-     * @return boolean success flag
-     */
-
-    public function dropIndex($table, $name)
-    {
-        $res = $this->conn->query("ALTER TABLE $table DROP INDEX $name");
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        return true;
-    }
-
-    /**
-     * Adds a column to a table
-     *
-     * @param string    $table     name of the table
-     * @param ColumnDef $columndef Definition of the new
-     *                             column.
-     *
-     * @return boolean success flag
-     */
-
-    public function addColumn($table, $columndef)
-    {
-        $sql = "ALTER TABLE $table ADD COLUMN " . $this->_columnSql($columndef);
-
-        $res = $this->conn->query($sql);
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        return true;
-    }
-
-    /**
-     * Modifies a column in the schema.
-     *
-     * The name must match an existing column and table.
-     *
-     * @param string    $table     name of the table
-     * @param ColumnDef $columndef new definition of the column.
-     *
-     * @return boolean success flag
-     */
-
-    public function modifyColumn($table, $columndef)
-    {
-        $sql = "ALTER TABLE $table MODIFY COLUMN " .
-          $this->_columnSql($columndef);
-
-        $res = $this->conn->query($sql);
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        return true;
-    }
-
-    /**
-     * Drops a column from a table
-     *
-     * The name must match an existing column.
-     *
-     * @param string $table      name of the table
-     * @param string $columnName name of the column to drop
-     *
-     * @return boolean success flag
-     */
-
-    public function dropColumn($table, $columnName)
-    {
-        $sql = "ALTER TABLE $table DROP COLUMN $columnName";
-
-        $res = $this->conn->query($sql);
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        return true;
-    }
-
     /**
      * Ensures that a table exists with the given
      * name and the given column definitions.
@@ -589,44 +414,12 @@ class MysqlSchema extends Schema
     }
 
     /**
-     * Returns the array of names from an array of
-     * ColumnDef objects.
-     *
-     * @param array $cds array of ColumnDef objects
-     *
-     * @return array strings for name values
-     */
-
-    private function _names($cds)
-    {
-        $names = array();
-
-        foreach ($cds as $cd) {
-            $names[] = $cd->name;
-        }
-
-        return $names;
-    }
-
-    /**
-     * Get a ColumnDef from an array matching
-     * name.
-     *
-     * @param array  $cds  Array of ColumnDef objects
-     * @param string $name Name of the column
-     *
-     * @return ColumnDef matching item or null if no match.
+     * Is this column a string type?
      */
-
-    private function _byName($cds, $name)
+    private function _isString(array $cd)
     {
-        foreach ($cds as $cd) {
-            if ($cd->name == $name) {
-                return $cd;
-            }
-        }
-
-        return null;
+        $strings = array('char', 'varchar', 'text');
+        return in_array(strtolower($cd['type']), $strings);
     }
 
     /**
@@ -641,43 +434,61 @@ class MysqlSchema extends Schema
      * @return string correct SQL for that column
      */
 
-    private function _columnSql($cd)
+    function columnSql(array $cd)
     {
-        $sql = "{$cd->name} ";
+        $line = array();
+        $line[] = parent::_columnSql($cd);
 
-        if (!empty($cd->size)) {
-            $sql .= "{$cd->type}({$cd->size}) ";
-        } else {
-            $sql .= "{$cd->type} ";
+        if ($cd['type'] == 'serial') {
+            $line[] = 'auto_increment';
         }
 
-        if ($this->_isString($cd)) {
-            $sql .= " CHARACTER SET utf8 ";
+        if (!empty($cd['extra'])) {
+            $line[] = $cd['extra']; // hisss boooo
         }
 
-        if (!empty($cd->default)) {
-            $sql .= "default {$cd->default} ";
-        } else {
-            $sql .= ($cd->nullable) ? "null " : "not null ";
-        }
-        
-        if (!empty($cd->auto_increment)) {
-            $sql .= " auto_increment ";
+        if (!empty($cd['description'])) {
+            $line[] = 'comment';
+            $line[] = $this->quote($cd['description']);
         }
 
-        if (!empty($cd->extra)) {
-            $sql .= "{$cd->extra} ";
+        return implode(' ', $line);
+    }
+
+    function mapType($column)
+    {
+        $map = array('serial' => 'int',
+                     'integer' => 'int',
+                     'numeric' => 'decimal');
+        
+        $type = $column['type'];
+        if (isset($map[$type])) {
+            $type = $map[$type];
+        }
+
+        if (!empty($column['size'])) {
+            $size = $column['size'];
+            if ($type == 'int' &&
+                       in_array($size, array('tiny', 'small', 'medium', 'big'))) {
+                $type = $size . $type;
+            } else if (in_array($type, array('blob', 'text')) &&
+                       in_array($size, array('tiny', 'medium', 'long'))) {
+                $type = $size . $type;
+            }
         }
 
-        return $sql;
+        return $type;
     }
 
-    /**
-     * Is this column a string type?
-     */
-    private function _isString(ColumnDef $cd)
+    function typeAndSize($column)
     {
-        $strings = array('char', 'varchar', 'text');
-        return in_array(strtolower($cd->type), $strings);
+        if ($column['type'] == 'enum') {
+            $vals = array_map(array($this, 'quote'), $column['enum']);
+            return 'enum(' . implode(',', $vals) . ')';
+        } else if ($this->_isString($column)) {
+            return parent::typeAndSize($column) . ' CHARSET utf8';
+        } else {
+            return parent::typeAndSize($column);
+        }
     }
 }
index 272f7eff683f354e5ca72a42401e7e0ddd0c5c4c..2d0f60983618a87ebaa8026b72599e3602faa441 100644 (file)
@@ -103,31 +103,6 @@ class PgsqlSchema extends Schema
         return $td;
     }
 
-    /**
-     * Gets a ColumnDef object for a single column.
-     *
-     * Throws an exception if the table is not found.
-     *
-     * @param string $table  name of the table
-     * @param string $column name of the column
-     *
-     * @return ColumnDef definition of the column or null
-     *                   if not found.
-     */
-
-    public function getColumnDef($table, $column)
-    {
-        $td = $this->getTableDef($table);
-
-        foreach ($td->columns as $cd) {
-            if ($cd->name == $column) {
-                return $cd;
-            }
-        }
-
-        return null;
-    }
-
     /**
      * Creates a table with the given names and columns.
      *
@@ -192,27 +167,6 @@ class PgsqlSchema extends Schema
         return true;
     }
 
-    /**
-     * Drops a table from the schema
-     *
-     * Throws an exception if the table is not found.
-     *
-     * @param string $name Name of the table to drop
-     *
-     * @return boolean success flag
-     */
-
-    public function dropTable($name)
-    {
-        $res = $this->conn->query("DROP TABLE $name");
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        return true;
-    }
-
     /**
      * Translate the (mostly) mysql-ish column types into somethings more standard
      * @param string column type
@@ -229,86 +183,6 @@ class PgsqlSchema extends Schema
       return $type;
     }
 
-    /**
-     * Adds an index to a table.
-     *
-     * If no name is provided, a name will be made up based
-     * on the table name and column names.
-     *
-     * Throws an exception on database error, esp. if the table
-     * does not exist.
-     *
-     * @param string $table       Name of the table
-     * @param array  $columnNames Name of columns to index
-     * @param string $name        (Optional) name of the index
-     *
-     * @return boolean success flag
-     */
-
-    public function createIndex($table, $columnNames, $name=null)
-    {
-        if (!is_array($columnNames)) {
-            $columnNames = array($columnNames);
-        }
-
-        if (empty($name)) {
-            $name = "$table_".implode("_", $columnNames)."_idx";
-        }
-
-        $res = $this->conn->query("ALTER TABLE $table ".
-                                   "ADD INDEX $name (".
-                                   implode(",", $columnNames).")");
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        return true;
-    }
-
-    /**
-     * Drops a named index from a table.
-     *
-     * @param string $table name of the table the index is on.
-     * @param string $name  name of the index
-     *
-     * @return boolean success flag
-     */
-
-    public function dropIndex($table, $name)
-    {
-        $res = $this->conn->query("ALTER TABLE $table DROP INDEX $name");
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        return true;
-    }
-
-    /**
-     * Adds a column to a table
-     *
-     * @param string    $table     name of the table
-     * @param ColumnDef $columndef Definition of the new
-     *                             column.
-     *
-     * @return boolean success flag
-     */
-
-    public function addColumn($table, $columndef)
-    {
-        $sql = "ALTER TABLE $table ADD COLUMN " . $this->_columnSql($columndef);
-
-        $res = $this->conn->query($sql);
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        return true;
-    }
-
     /**
      * Modifies a column in the schema.
      *
@@ -334,29 +208,6 @@ class PgsqlSchema extends Schema
         return true;
     }
 
-    /**
-     * Drops a column from a table
-     *
-     * The name must match an existing column.
-     *
-     * @param string $table      name of the table
-     * @param string $columnName name of the column to drop
-     *
-     * @return boolean success flag
-     */
-
-    public function dropColumn($table, $columnName)
-    {
-        $sql = "ALTER TABLE $table DROP COLUMN $columnName";
-
-        $res = $this->conn->query($sql);
-
-        if (PEAR::isError($res)) {
-            throw new Exception($res->getMessage());
-        }
-
-        return true;
-    }
 
     /**
      * Ensures that a table exists with the given
@@ -445,88 +296,68 @@ class PgsqlSchema extends Schema
     }
 
     /**
-     * Returns the array of names from an array of
-     * ColumnDef objects.
-     *
-     * @param array $cds array of ColumnDef objects
+     * Return the proper SQL for creating or
+     * altering a column.
      *
-     * @return array strings for name values
-     */
-
-    private function _names($cds)
-    {
-        $names = array();
-
-        foreach ($cds as $cd) {
-            $names[] = $cd->name;
-        }
-
-        return $names;
-    }
-
-    /**
-     * Get a ColumnDef from an array matching
-     * name.
+     * Appropriate for use in CREATE TABLE or
+     * ALTER TABLE statements.
      *
-     * @param array  $cds  Array of ColumnDef objects
-     * @param string $name Name of the column
+     * @param string $tableName
+     * @param array $tableDef
+     * @param string $columnName
+     * @param array $cd column to create
      *
-     * @return ColumnDef matching item or null if no match.
+     * @return string correct SQL for that column
      */
 
-    private function _byName($cds, $name)
+    function columnSql($name, array $cd)
     {
-        foreach ($cds as $cd) {
-            if ($cd->name == $name) {
-                return $cd;
+        $line = array();
+        $line[] = parent::_columnSql($cd);
+
+        if ($table['foreign keys'][$name]) {
+            foreach ($table['foreign keys'][$name] as $foreignTable => $foreignColumn) {
+                $line[] = 'references';
+                $line[] = $this->quoteId($foreignTable);
+                $line[] = '(' . $this->quoteId($foreignColumn) . ')';
             }
         }
 
-        return null;
+        return implode(' ', $line);
     }
 
-    /**
-     * Return the proper SQL for creating or
-     * altering a column.
-     *
-     * Appropriate for use in CREATE TABLE or
-     * ALTER TABLE statements.
-     *
-     * @param ColumnDef $cd column to create
-     *
-     * @return string correct SQL for that column
-     */
-    private function _columnSql($cd)
+    function mapType($column)
     {
-        $sql = "{$cd->name} ";
-        $type = $this->_columnTypeTranslation($cd->type);
-
-        //handle those mysql enum fields that postgres doesn't support
-        if (preg_match('!^enum!', $type)) {
-          $allowed_values = preg_replace('!^enum!', '', $type);
-          $sql .= " text check ({$cd->name} in $allowed_values)";
-          return $sql;
-        }
-        if (!empty($cd->auto_increment)) {
-           $type = "bigserial"; // FIXME: creates the wrong name for the sequence for some internal sequence-lookup function, so better fix this to do the real 'create sequence' dance.
+        $map = array('serial' => 'bigserial', // FIXME: creates the wrong name for the sequence for some internal sequence-lookup function, so better fix this to do the real 'create sequence' dance.
+                     'numeric' => 'decimal',
+                     'datetime' => 'timestamp',
+                     'blob' => 'bytea');
+
+        $type = $column['type'];
+        if (isset($map[$type])) {
+            $type = $map[$type];
         }
 
-        if (!empty($cd->size)) {
-            $sql .= "{$type}({$cd->size}) ";
-        } else {
-            $sql .= "{$type} ";
+        if (!empty($column['size'])) {
+            $size = $column['size'];
+            if ($type == 'integer' &&
+                       in_array($size, array('small', 'big'))) {
+                $type = $size . 'int';
+            }
         }
 
-        if (!empty($cd->default)) {
-            $sql .= "default {$cd->default} ";
+        return $type;
+    }
+
+    // @fixme need name... :P
+    function typeAndSize($column)
+    {
+        if ($column['type'] == 'enum') {
+            $vals = array_map(array($this, 'quote'), $column['enum']);
+            return "text check ($name in " . implode(',', $vals) . ')';
         } else {
-            $sql .= ($cd->nullable) ? "null " : "not null ";
+            return parent::typeAndSize($column);
         }
-
-//         if (!empty($cd->extra)) {
-//             $sql .= "{$cd->extra} ";
-//         }
-
-        return $sql;
     }
+
 }
index e5def514e31ddbc227ecb2a6afaec272c9c5d2dc..d20bced4a740e056deab2b183c921adf05c643c9 100644 (file)
@@ -41,6 +41,7 @@ if (!defined('STATUSNET')) {
  * @category Database
  * @package  StatusNet
  * @author   Evan Prodromou <evan@status.net>
+ * @author   Brion Vibber <brion@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
  */
@@ -223,7 +224,7 @@ class Schema
         }
 
         if (empty($name)) {
-            $name = "$table_".implode("_", $columnNames)."_idx";
+            $name = "{$table}_".implode("_", $columnNames)."_idx";
         }
 
         $res = $this->conn->query("ALTER TABLE $table ".
@@ -421,7 +422,7 @@ class Schema
      * @return array strings for name values
      */
 
-    private function _names($cds)
+    protected function _names($cds)
     {
         $names = array();
 
@@ -442,7 +443,7 @@ class Schema
      * @return ColumnDef matching item or null if no match.
      */
 
-    private function _byName($cds, $name)
+    protected function _byName($cds, $name)
     {
         foreach ($cds as $cd) {
             if ($cd->name == $name) {
@@ -465,31 +466,122 @@ class Schema
      * @return string correct SQL for that column
      */
 
-    private function _columnSql($cd)
+    function columnSql(array $cd)
     {
-        $sql = "{$cd->name} ";
+        $line = array();
+        $line[] = $this->typeAndSize();
+
+        if (isset($cd['default'])) {
+            $line[] = 'default';
+            $line[] = $this->quoted($cd['default']);
+        } else if (!empty($cd['not null'])) {
+            // Can't have both not null AND default!
+            $line[] = 'not null';
+        }
 
-        if (!empty($cd->size)) {
-            $sql .= "{$cd->type}({$cd->size}) ";
-        } else {
-            $sql .= "{$cd->type} ";
+        return implode(' ', $line);
+    }
+
+    /**
+     *
+     * @param string $column canonical type name in defs
+     * @return string native DB type name
+     */
+    function mapType($column)
+    {
+        return $column;
+    }
+
+    function typeAndSize($column)
+    {
+        $type = $this->mapType($column);
+        $lengths = array();
+
+        if ($column['type'] == 'numeric') {
+            if (isset($column['precision'])) {
+                $lengths[] = $column['precision'];
+                if (isset($column['scale'])) {
+                    $lengths[] = $column['scale'];
+                }
+            }
+        } else if (isset($column['length'])) {
+            $lengths[] = $column['length'];
         }
 
-        if (!empty($cd->default)) {
-            $sql .= "default {$cd->default} ";
+        if ($lengths) {
+            return $type . '(' . implode(',', $lengths) . ')';
         } else {
-            $sql .= ($cd->nullable) ? "null " : "not null ";
+            return $type;
         }
+    }
 
-        if (!empty($cd->auto_increment)) {
-            $sql .= " auto_increment ";
-        }
+    /**
+     * Convert an old-style set of ColumnDef objects into the current
+     * Drupal-style schema definition array, for backwards compatibility
+     * with plugins written for 0.9.x.
+     *
+     * @param string $tableName
+     * @param array $defs
+     * @return array
+     */
+    function oldToNew($tableName, $defs)
+    {
+        $table = array();
+        $prefixes = array(
+            'tiny',
+            'small',
+            'medium',
+            'big',
+        );
+        foreach ($defs as $cd) {
+            $cd->addToTableDef($table);
+            $column = array();
+            $column['type'] = $cd->type;
+            foreach ($prefixes as $prefix) {
+                if (substr($cd->type, 0, strlen($prefix)) == $prefix) {
+                    $column['type'] = substr($cd->type, strlen($prefix));
+                    $column['size'] = $prefix;
+                    break;
+                }
+            }
 
-        if (!empty($cd->extra)) {
-            $sql .= "{$cd->extra} ";
+            if ($cd->size) {
+                if ($cd->type == 'varchar' || $cd->type == 'char') {
+                    $column['length'] = $cd->size;
+                }
+            }
+            if (!$cd->nullable) {
+                $column['not null'] = true;
+            }
+            if ($cd->autoincrement) {
+                $column['type'] = 'serial';
+            }
+            if ($cd->default) {
+                $column['default'] = $cd->default;
+            }
+            $table['fields'][$cd->name] = $column;
+
+            if ($cd->key == 'PRI') {
+                // If multiple columns are defined as primary key,
+                // we'll pile them on in sequence.
+                if (!isset($table['primary key'])) {
+                    $table['primary key'] = array();
+                }
+                $table['primary key'][] = $cd->name;
+            } else if ($cd->key == 'MUL') {
+                // Individual multiple-value indexes are only per-column
+                // using the old ColumnDef syntax.
+                $idx = "{$tableName}_{$cd->name}_idx";
+                $table['indexes'][$idx] = array($cd->name);
+            } else if ($cd->key == 'UNI') {
+                // Individual unique-value indexes are only per-column
+                // using the old ColumnDef syntax.
+                $idx = "{$tableName}_{$cd->name}_idx";
+                $table['unique keys'][$idx] = array($cd->name);
+            }
         }
 
-        return $sql;
+        return $table;
     }
 }
 
diff --git a/plugins/CacheLog/locale/nb/LC_MESSAGES/CacheLog.po b/plugins/CacheLog/locale/nb/LC_MESSAGES/CacheLog.po
deleted file mode 100644 (file)
index 1ba685a..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-# Translation of StatusNet - CacheLog to Norwegian (bokmål)‬ (‪Norsk (bokmål)‬)
-# Expored from translatewiki.net
-#
-# Author: Nghtwlkr
-# --
-# This file is distributed under the same license as the StatusNet package.
-#
-msgid ""
-msgstr ""
-"Project-Id-Version: StatusNet - CacheLog\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2010-10-04 22:30+0000\n"
-"PO-Revision-Date: 2010-10-04 22:32:56+0000\n"
-"Language-Team: Norwegian (bokmål)‬ <http://translatewiki.net/wiki/Portal:no>\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"X-POT-Import-Date: 2010-10-03 20:56:06+0000\n"
-"X-Generator: MediaWiki 1.17alpha (r74276); Translate extension (2010-09-17)\n"
-"X-Translation-Project: translatewiki.net at http://translatewiki.net\n"
-"X-Language-Code: no\n"
-"X-Message-Group: #out-statusnet-plugin-cachelog\n"
-"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-
-#: CacheLogPlugin.php:116
-msgid "Log reads and writes to the cache."
-msgstr "Logg leser og skriver til hurtiglageret."
index 10cee917e1163a906d94b8d3a25ce7749c794a1a..ee126c02a19dea1eca574d616724a3b643c70830 100644 (file)
@@ -21,7 +21,8 @@
  * @package OStatusPlugin
  * @maintainer Brion Vibber <brion@status.net>
  */
-class Ostatus_profile extends Memcached_DataObject
+
+class Ostatus_profile extends Managed_DataObject
 {
     public $__table = 'ostatus_profile';
 
@@ -43,74 +44,35 @@ class Ostatus_profile extends Memcached_DataObject
     }
 
     /**
-     * return table definition for DB_DataObject
-     *
-     * DB_DataObject needs to know something about the table to manipulate
-     * instances. This method provides all the DB_DataObject needs to know.
+     * Return table definition for Schema setup and DB_DataObject usage.
      *
      * @return array array of column definitions
      */
-    function table()
-    {
-        return array('uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'profile_id' => DB_DATAOBJECT_INT,
-                     'group_id' => DB_DATAOBJECT_INT,
-                     'feeduri' => DB_DATAOBJECT_STR,
-                     'salmonuri' =>  DB_DATAOBJECT_STR,
-                     'avatar' =>  DB_DATAOBJECT_STR,
-                     'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
-                     'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
-    }
 
     static function schemaDef()
     {
-        return array(new ColumnDef('uri', 'varchar',
-                                   255, false, 'PRI'),
-                     new ColumnDef('profile_id', 'integer',
-                                   null, true, 'UNI'),
-                     new ColumnDef('group_id', 'integer',
-                                   null, true, 'UNI'),
-                     new ColumnDef('feeduri', 'varchar',
-                                   255, true, 'UNI'),
-                     new ColumnDef('salmonuri', 'text',
-                                   null, true),
-                     new ColumnDef('avatar', 'text',
-                                   null, true),
-                     new ColumnDef('created', 'datetime',
-                                   null, false),
-                     new ColumnDef('modified', 'datetime',
-                                   null, false));
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * DB_DataObject needs to know about keys that the table has; this function
-     * defines them.
-     *
-     * @return array key definitions
-     */
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
-
-    /**
-     * return key definitions for Memcached_DataObject
-     *
-     * Our caching system uses the same key definitions, but uses a different
-     * method to get them.
-     *
-     * @return array key definitions
-     */
-    function keyTypes()
-    {
-        return array('uri' => 'K', 'profile_id' => 'U', 'group_id' => 'U', 'feeduri' => 'U');
-    }
-
-    function sequenceKey()
-    {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'uri' => array('type' => 'varchar', 'length' => 255, 'not null' => true),
+                'profile_id' => array('type' => 'integer'),
+                'group_id' => array('type' => 'integer'),
+                'feeduri' => array('type' => 'varchar', 'length' => 255),
+                'salmonuri' => array('type' => 'varchar', 'length' => 255),
+                'avatar' => array('type' => 'text'),
+                'created' => array('type' => 'datetime', 'not null' => true),
+                'modified' => array('type' => 'datetime', 'not null' => true),
+            ),
+            'primary key' => array('uri'),
+            'unique keys' => array(
+                'ostatus_profile_profile_id_idx' => array('profile_id'),
+                'ostatus_profile_group_id_idx' => array('group_id'),
+                'ostatus_profile_feeduri_idx' => array('feeduri'),
+            ),
+            'foreign keys' => array(
+                'profile_id' => array('profile' => 'id'),
+                'group_id' => array('user_group' => 'id'),
+            ),
+        );
     }
 
     /**