]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
IMPORTANT: Making prev. Memcached_DataObject working again with schemaDef
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 19 Aug 2013 15:08:18 +0000 (17:08 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Wed, 21 Aug 2013 07:48:42 +0000 (09:48 +0200)
Lots of the Memcached_DataObject classes stopped working when upgraded to
Managed_DataObject because they lacked schemaDef().

I have _hopefully_ made it so that all the references to the table uses
each class' schemaDef, rather than the more manual ColumnDef stuff. Not
all plugins have been tested thoroughly yet.

NOTE: This is applied with getKV calls instead of staticGet, as it was
important for PHP Strict Standards compliance to avoid calling the non-
static functions statically. (unfortunately DB and DB_DataObject still do
this within themselves...)

42 files changed:
classes/User_username.php
lib/authenticationplugin.php
plugins/AnonymousFave/AnonymousFavePlugin.php
plugins/AnonymousFave/Fave_tally.php
plugins/Blacklist/BlacklistPlugin.php
plugins/Blacklist/Homepage_blacklist.php
plugins/Blacklist/Nickname_blacklist.php
plugins/EmailSummary/EmailSummaryPlugin.php
plugins/EmailSummary/Email_summary_status.php
plugins/FollowEveryone/FollowEveryonePlugin.php
plugins/FollowEveryone/User_followeveryone_prefs.php
plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
plugins/GNUsocialPhotos/classes/gnusocialphoto.php
plugins/GNUsocialPhotos/classes/gnusocialphotoalbum.php
plugins/GNUsocialProfileExtensions/GNUsocialProfileExtensionsPlugin.php
plugins/GNUsocialProfileExtensions/classes/GNUsocialProfileExtensionField.php
plugins/GNUsocialProfileExtensions/classes/GNUsocialProfileExtensionResponse.php
plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php
plugins/GroupPrivateMessage/Group_message.php
plugins/GroupPrivateMessage/Group_message_profile.php
plugins/GroupPrivateMessage/Group_privacy_settings.php
plugins/Irc/IrcPlugin.php
plugins/Irc/Irc_waiting_message.php
plugins/Msn/MsnPlugin.php
plugins/Msn/msn_waiting_message.php
plugins/NoticeTitle/NoticeTitlePlugin.php
plugins/NoticeTitle/Notice_title.php
plugins/OpenID/OpenIDPlugin.php
plugins/OpenID/User_openid.php
plugins/OpenID/User_openid_trustroot.php
plugins/RegisterThrottle/RegisterThrottlePlugin.php
plugins/RegisterThrottle/Registration_ip.php
plugins/Sample/SamplePlugin.php
plugins/Sample/User_greeting_count.php
plugins/Sitemap/SitemapPlugin.php
plugins/Sitemap/Sitemap_notice_count.php
plugins/Sitemap/Sitemap_user_count.php
plugins/TwitterBridge/Notice_to_status.php
plugins/TwitterBridge/TwitterBridgePlugin.php
plugins/TwitterBridge/Twitter_synch_status.php
plugins/UserFlag/UserFlagPlugin.php
plugins/UserFlag/User_flag_profile.php

index 31dc66faeaf041f1b343b91d28a1e8716136bd0d..5f0ef63185208e05163aa5d0bfb2fb8fb2a64f20 100644 (file)
@@ -19,6 +19,23 @@ class User_username extends Managed_DataObject
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
+    public static function schemaDef()
+    {
+        return array(
+            'fields' => array(
+                'provider_name' => array('type' => 'varchar', 'length' => 255, 'description' => 'provider name'),
+                'username' => array('type' => 'varchar', 'length' => 255, 'description' => 'username'),
+                'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id this title relates to'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('provider_name', 'username'),
+            'foreign keys' => array(
+                'user_username_user_id_fkey' => array('user', array('user_id' => 'id')),
+            ),
+        );
+    }
+
     /**
     * Register a user with a username on a given provider
     * @param User User object
@@ -40,18 +57,4 @@ class User_username extends Managed_DataObject
             return false;
         }
     }
-
-    function table() {
-        return array(
-            'user_id'     => DB_DATAOBJECT_INT,
-            'username'   => DB_DATAOBJECT_STR,
-            'provider_name'   => DB_DATAOBJECT_STR ,
-            'created'   => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME
-        );
-    }
-
-    // now define the keys.
-    function keys() {
-        return array('provider_name' => 'K', 'username' => 'K');
-    }
 }
index ad031e785240941a2516d7ed20c9af719ee0bfce..bf5f3aafe3a06f3d0c75eebac2f1e07a9880f517 100644 (file)
@@ -250,16 +250,7 @@ abstract class AuthenticationPlugin extends Plugin
 
     function onCheckSchema() {
         $schema = Schema::get();
-        $schema->ensureTable('user_username',
-                             array(new ColumnDef('provider_name', 'varchar',
-                                                 '255', false, 'PRI'),
-                                   new ColumnDef('username', 'varchar',
-                                                 '255', false, 'PRI'),
-                                   new ColumnDef('user_id', 'integer',
-                                                 null, false),
-                                   new ColumnDef('created', 'datetime',
-                                                 null, false),
-                                   new ColumnDef('modified', 'timestamp')));
+        $schema->ensureTable('user_username', User_username::schemaDef());
         return true;
     }
 
index c3f810d6ee0a4c3f905faeba228adf386c829a93..e0b2a17d1fef126cf88735c314405f5c9b313b25 100644 (file)
@@ -80,22 +80,7 @@ class AnonymousFavePlugin extends Plugin
         $schema = Schema::get();
 
         // For storing total number of times a notice has been faved
-
-        $schema->ensureTable('fave_tally',
-            array(
-                new ColumnDef('notice_id', 'integer', null,  false, 'PRI'),
-                new ColumnDef('count', 'integer', null, false),
-                new ColumnDef(
-                    'modified',
-                    'timestamp',
-                    null,
-                    false,
-                    null,
-                    'CURRENT_TIMESTAMP',
-                    'on update CURRENT_TIMESTAMP'
-                )
-            )
-        );
+        $schema->ensureTable('fave_tally', Fave_tally::schemaDef());
 
         return true;
     }
index eb23a7cb0ab150766e9f01086fb60e2bba25d6ec..c9fe181b6d5c5dea1b7aefb6c3f4251ff36567ec 100644 (file)
@@ -52,72 +52,28 @@ class Fave_tally extends Managed_DataObject
     public $__table = 'fave_tally';          // table name
     public $notice_id;                       // int(4)  primary_key not_null
     public $count;                           // int(4)  not_null
+    public $created;                         // datetime()   not_null
     public $modified;                        // datetime   not_null default_0000-00-00%2000%3A00%3A00
 
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
-    /**
-     * return table definition for DB_DataObject
-     *
-     * @return array array of column definitions
-     */
-
-    function table()
+    public static function schemaDef()
     {
         return array(
-            'notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-            'count'     => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-            'modified'  => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL
+            'fields' => array(
+                'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id'),
+                'count' => array('type' => 'int', 'not null' => true, 'description' => 'the fave tally count'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('notice_id'),
+            'foreign keys' => array(
+                'fave_tally_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
+            ),
         );
     }
 
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * DB_DataObject needs to know about keys that the table has, since it
-     * won't appear in StatusNet's own keys list. In most cases, this will
-     * simply reference your keyTypes() function.
-     *
-     * @return array list of key field names
-     */
-    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. This key information is used to store and clear
-     * cached data, so be sure to list any key that will be used for static
-     * lookups.
-     *
-     * @return array associative array of key definitions, field name to type:
-     *         'K' for primary key: for compound keys, add an entry for each component;
-     *         'U' for unique keys: compound keys are not well supported here.
-     */
-    function keyTypes()
-    {
-        return array('notice_id' => 'K');
-    }
-
-    /**
-     * Magic formula for non-autoincrementing integer primary keys
-     *
-     * If a table has a single integer column as its primary key, DB_DataObject
-     * assumes that the column is auto-incrementing and makes a sequence table
-     * to do this incrementation. Since we don't need this for our class, we
-     * overload this method and return the magic formula that DB_DataObject needs.
-     *
-     * @return array magic three-false array that stops auto-incrementing.
-     */
-    function sequenceKey()
-    {
-        return array(false, false, false);
-    }
-
     /**
      * Increment a notice's tally
      *
index e0d2a04dd823537b4395822de42aac53821c6477..5f31be63d472178ac7a74f874521c0a2016cb8c5 100644 (file)
@@ -80,27 +80,8 @@ class BlacklistPlugin extends Plugin
         $schema = Schema::get();
 
         // For storing blacklist patterns for nicknames
-        $schema->ensureTable('nickname_blacklist',
-                             array(new ColumnDef('pattern',
-                                                 'varchar',
-                                                 255,
-                                                 false,
-                                                 'PRI'),
-                                   new ColumnDef('created',
-                                                 'datetime',
-                                                 null,
-                                                 false)));
-
-        $schema->ensureTable('homepage_blacklist',
-                             array(new ColumnDef('pattern',
-                                                 'varchar',
-                                                 255,
-                                                 false,
-                                                 'PRI'),
-                                   new ColumnDef('created',
-                                                 'datetime',
-                                                 null,
-                                                 false)));
+        $schema->ensureTable('nickname_blacklist', Nickname_blacklist::schemaDef());
+        $schema->ensureTable('homepage_blacklist', Homepage_blacklist::schemaDef());
 
         return true;
     }
index 440084702cece0c19ed9e90737f2d4f41a525808..fb2712f5658189c7e25eaff70ed37bfaae0ab461 100644 (file)
@@ -47,47 +47,20 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
 class Homepage_blacklist extends Managed_DataObject
 {
     public $__table = 'homepage_blacklist'; // table name
-    public $pattern;                        // string pattern
-    public $created;                        // datetime
+    public $pattern;                        // varchar(255) pattern
+    public $created;                        // datetime not_null
+    public $modified;                       // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
-    {
-        return array('pattern' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
-    }
-
-    /**
-     * 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()
+    public static function schemaDef()
     {
-        return array('pattern' => 'K');
+        return array(
+            'fields' => array(
+                'pattern' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'blacklist pattern'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('pattern'),
+        );
     }
 
     /**
index bf1d1e5ab7310b56a1aafdeabaafc4310beb4f64..f4f387a2e02e6524a46d96c77d83dd0937d1bae2 100644 (file)
@@ -47,38 +47,20 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
 class Nickname_blacklist extends Managed_DataObject
 {
     public $__table = 'nickname_blacklist'; // table name
-    public $pattern;                        // string pattern
-    public $created;                        // datetime
+    public $pattern;                        // varchar(255) pattern
+    public $created;                        // datetime not_null
+    public $modified;                       // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    /**
-     * return table definition for DB_DataObject
-     *
-     * @return array array of column definitions
-     */
-    function table()
-    {
-        return array('pattern' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * @return array key definitions
-     */
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
-
-    /**
-     * return key definitions for Memcached_DataObject
-     *
-     * @return array key definitions
-     */
-    function keyTypes()
+    public static function schemaDef()
     {
-        return array('pattern' => 'K');
+        return array(
+            'fields' => array(
+                'pattern' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'blacklist pattern'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('pattern'),
+        );
     }
 
     /**
index 15cc0b5bd83191986d0e99bac89d642017c330c9..f99a10bc02c9954709d61e556ae10699c5362da4 100644 (file)
@@ -55,19 +55,7 @@ class EmailSummaryPlugin extends Plugin
         $schema = Schema::get();
 
         // For storing user-submitted flags on profiles
-        $schema->ensureTable('email_summary_status',
-                             array(new ColumnDef('user_id', 'integer', null,
-                                                 false, 'PRI'),
-                                   new ColumnDef('send_summary', 'tinyint', null,
-                                                 false, null, 1),
-                                   new ColumnDef('last_summary_id', 'integer', null,
-                                                 true),
-                                   new ColumnDef('created', 'datetime', null,
-                                                 false),
-                                   new ColumnDef('modified', 'datetime', null,
-                                                 false),
-                             )
-        );
+        $schema->ensureTable('email_summary_status', Email_summary_status::schemaDef());
         return true;
     }
 
index de9e491fa6aea2c544e6289eb8bbfcf6d4f059fe..460053f9f858de1aae2de808b0ead313eb3374d6 100644 (file)
@@ -55,58 +55,21 @@ class Email_summary_status extends Managed_DataObject
     public $created;                         // datetime not_null
     public $modified;                        // datetime not_null
 
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
-    {
-        return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'send_summary' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'last_summary_id' => DB_DATAOBJECT_INT,
-                     'created' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
-                     'modified' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * @return array list of key field names
-     */
-    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. This key information is used to store and clear
-     * cached data, so be sure to list any key that will be used for static
-     * lookups.
-     *
-     * @return array associative array of key definitions, field name to type:
-     *         'K' for primary key: for compound keys, add an entry for each component;
-     *         'U' for unique keys: compound keys are not well supported here.
-     */
-    function keyTypes()
-    {
-        return array('user_id' => 'K');
-    }
-
-    /**
-     * Magic formula for non-autoincrementing integer primary keys
-     *
-     * @return array magic three-false array that stops auto-incrementing.
-     */
-    function sequenceKey()
+    public static function schemaDef()
     {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
+                'send_summary' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'not null' => true, 'description' => 'whether to send a summary or not'),
+                'last_summary_id' => array('type' => 'int', 'description' => 'last summary id'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),   
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('user_id'),
+            'foreign keys' => array(
+                'email_summary_status_user_id_fkey' => array('user', array('user_id' => 'id')),
+            ),
+        );
     }
 
     /**
index 98f61c3a99459f29fb495ff980496625b0bbfb11..0bea8d9aa46ed93041fd824cd5b38188a06b7eeb 100644 (file)
@@ -114,11 +114,7 @@ class FollowEveryonePlugin extends Plugin
         $schema = Schema::get();
 
         // For storing user-submitted flags on profiles
-        $schema->ensureTable('user_followeveryone_prefs',
-                             array(new ColumnDef('user_id', 'integer', null,
-                                                 true, 'PRI'),
-                                   new ColumnDef('followeveryone', 'tinyint', null,
-                                                 false, null, 1)));
+        $schema->ensureTable('user_followeveryone_prefs', User_followeveryone_prefs::schemaDef());
 
         return true;
     }
index 79e3bfa1300bc89f64296f6e54b6c1b4c7ee4cbf..c1a654df92d88b077e14293fc35bfbd2206a8f9b 100644 (file)
@@ -57,65 +57,23 @@ class User_followeveryone_prefs extends Managed_DataObject
     public $__table = 'user_followeveryone_prefs'; // table name
     public $user_id;                               // int(4)  primary_key not_null
     public $followeveryone;                        // tinyint(1)
+    public $created;                               // datetime()   not_null
+    public $modified;                              // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
+    public static function schemaDef()
     {
-        return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'followeveryone' => DB_DATAOBJECT_INT + DB_DATAOBJECT_BOOL);
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * DB_DataObject needs to know about keys that the table has, since it
-     * won't appear in StatusNet's own keys list. In most cases, this will
-     * simply reference your keyTypes() function.
-     *
-     * @return array list of key field names
-     */
-    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. This key information is used to store and clear
-     * cached data, so be sure to list any key that will be used for static
-     * lookups.
-     *
-     * @return array associative array of key definitions, field name to type:
-     *         'K' for primary key: for compound keys, add an entry for each component;
-     *         'U' for unique keys: compound keys are not well supported here.
-     */
-    function keyTypes()
-    {
-        return array('user_id' => 'K');
-    }
-
-    /**
-     * Magic formula for non-autoincrementing integer primary keys
-     *
-     * If a table has a single integer column as its primary key, DB_DataObject
-     * assumes that the column is auto-incrementing and makes a sequence table
-     * to do this incrementation. Since we don't need this for our class, we
-     * overload this method and return the magic formula that DB_DataObject needs.
-     *
-     * @return array magic three-false array that stops auto-incrementing.
-     */
-    function sequenceKey()
-    {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
+                'followeveryone' => array('type' => 'int', 'default' => 1, 'size' => 'tiny', 'description' => 'whether to follow everyone'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('user_id'),
+            'foreign keys' => array(
+                'user_followeveryone_prefs_user_id_fkey' => array('user', array('user_id' => 'id')),
+            ),
+        );
     }
 
     static function followEveryone($user_id)
index f187a22a775b8619b93242c8d92e39b2e5ee53ca..3a7e8822364fe200a3671931fd9d9cf6c842dd8c 100644 (file)
@@ -71,20 +71,8 @@ class GNUsocialPhotosPlugin extends Plugin
     function onCheckSchema()
     {
         $schema = Schema::get();
-        $schema->ensureTable('GNUsocialPhoto',
-                                array(new ColumnDef('id', 'int(11)', null, false, 'PRI', null, null, true),
-                                      new ColumnDef('notice_id', 'int(11)', null, false),
-                                      new ColumnDef('album_id', 'int(11)', null, false),
-                                      new ColumnDef('uri', 'varchar(512)', null, false),
-                                      new ColumnDef('thumb_uri', 'varchar(512)', null, false),
-                                      new ColumnDef('title', 'varchar(512)', null, false),
-                                      new ColumnDef('photo_description', 'text', null, false)));
-        $schema->ensureTable('GNUsocialPhotoAlbum',
-                                array(new ColumnDef('album_id', 'int(11)', null, false, 'PRI', null, null, true),
-                                      new ColumnDef('profile_id', 'int(11)', null, false),
-                                      new ColumnDef('album_name', 'varchar(256)', null, false),
-                                      new ColumnDef('album_description', 'text', null, false)));
-                                          
+        $schema->ensureTable('GNUsocialPhoto', GNUsocialPhoto::schemaDef());
+        $schema->ensureTable('GNUsocialPhotoAlbum', GNUsocialPhotoAlbum::schemaDef());
     }
 
     function onRouterInitialized($m)
index 3898d42994d299cc868827c28eb711341f374f80..6e9daac2ed8704c1ae2e82ba8a380059134ea190 100644 (file)
@@ -38,10 +38,12 @@ class GNUsocialPhoto extends Managed_DataObject
     public $id;         // int(11)
     public $notice_id;  // int(11)
     public $album_id;   // int(11)
-    public $uri;        // varchar(512)
-    public $thumb_uri;  // varchar(512)
-       public $title;      // varchar(512)
+    public $uri;        // varchar(255)
+    public $thumb_uri;  // varchar(255)
+       public $title;      // varchar(255)
        public $photo_description; // text
+    public $created;           // datetime()   not_null
+    public $modified;          // timestamp()   not_null default_CURRENT_TIMESTAMP
 
 /*    function delete()
     {
@@ -54,34 +56,32 @@ class GNUsocialPhoto extends Managed_DataObject
         return parent::delete();
     } */
 
-
-    /*
-     * TODO: Foriegn key on album_id.
-     */
-    function table()
-    {
-        return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'album_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'thumb_uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'title' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'photo_description' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
-    }
-    
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
-
-    function keyTypes()
-    {
-        return array('notice_id' => 'K');
-    }
-
-    function sequenceKey()
+    public static function schemaDef()
     {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique ID for Photo'),
+                'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'Notice ID for the related notice'),
+                'album_id' => array('type' => 'int', 'not null' => true, 'description' => 'The parent album ID'),
+                'uri' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'unique address for this photo'),
+                'thumb_uri' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'unique address for this photo thumbnail'),
+                'title' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'The Photo title'),
+                'photo_description' => array('type' => 'text', 'not null' => true, 'description' => 'A description for this photo'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('id'),
+            'unique keys' => array(
+                'gnusocialphoto_uri' => array('uri'),
+            ),
+            'foreign keys' => array(
+                'gnusocialphoto_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
+                'gnusocialphoto_album_id_fkey' => array('GNUsocialPhotoAlbum', array('album_id' => 'id')),
+            ),
+            'indexes' => array(
+                'gnusocialphoto_title_idx' => array('title'),
+            ),
+        );
     }
 
     function saveNew($profile_id, $album_id, $thumb_uri, $uri, $source, $insert_now, $title = null, $photo_description = null)
index 722a8f69ae11efc0c283a3a9feaa6eaf0be4d82b..208c341851d013a48271641175c1e8cbb9640a7f 100644 (file)
@@ -38,33 +38,31 @@ class GNUsocialPhotoAlbum extends Managed_DataObject
     public $__table = 'GNUsocialPhotoAlbum';
     public $album_id;          // int(11) -- Unique identifier for the album
     public $profile_id;        // int(11) -- Profile ID for the owner of the album
-    public $album_name;        // varchar(256) -- Title for this album
+    public $album_name;        // varchar(255) -- Title for this album
     public $album_description; // text -- A description of the album
+    public $created;           // datetime()   not_null
+    public $modified;          // timestamp()   not_null default_CURRENT_TIMESTAMP
     
     /* TODO: Primary key on both album_id, profile_id / foriegn key on profile_id */
-    function table()
+    public static function schemaDef()
     {
-        return array('album_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'album_name' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'album_description' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
-    }
-    
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
-
-    
-    /* Using album_id as the primary key for now.. */
-    function keyTypes()
-    {
-        return array('album_id' => 'K');
-    }
-
-    function sequenceKey()
-    {
-        return array('album_id', true, false);
+        return array(
+            'fields' => array(
+                'album_id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique identifier for the album'),
+                'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'Profile ID for the owner of the album'),
+                'album_name' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'Title for this album'),
+                'album_description' => array('type' => 'text', 'not null' => true, 'description' => 'A description for this album'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('user_id'),
+            'foreign keys' => array(
+                'gnusocialphotoalbum_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
+            ),
+            'indexes' => array(
+                'gnusocialphotoalbum_album_name_idx' => array('album_name'),
+            ),
+        );
     }
 
     function getPageLink()
index cf5fb0a067f3d1521028d519a86bb389b8dd6d4f..e6c961f86528960da44bcee2dfcbc170a6e48e86 100644 (file)
@@ -59,17 +59,8 @@ class GNUsocialProfileExtensionsPlugin extends Plugin
     function onCheckSchema()
     {
         $schema = Schema::get();
-        $schema->ensureTable('GNUsocialProfileExtensionField',
-                                array(new ColumnDef('id', 'int(11)', null, false, 'PRI', null, null, true),
-                                      new ColumnDef('systemname', 'varchar(64)', null, false),
-                                      new ColumnDef('title', 'varchar(256)', null, false),
-                                      new ColumnDef('description', 'text', null, false),
-                                      new ColumnDef('type', 'varchar(256)', null, false)));
-        $schema->ensureTable('GNUsocialProfileExtensionResponse',
-                                array(new ColumnDef('id', 'int(11)', null, false, 'PRI', null, null, true),
-                                      new ColumnDef('extension_id', 'int(11)', null, false),
-                                      new ColumnDef('profile_id', 'int(11)', null, false),
-                                      new ColumnDef('value', 'text', null, false)));
+        $schema->ensureTable('GNUsocialProfileExtensionField', GNUsocialProfileExtensionField::schemaDef());
+        $schema->ensureTable('GNUsocialProfileExtensionResponse', GNUsocialProfileExtensionResponse::schemaDef());
                                           
     }
 
index f8568c26e4e927f91d75e7fa76d6c0c3ccd98993..9574863c58be63d601823c09d8a9c0707c275230 100644 (file)
@@ -37,22 +37,29 @@ class GNUsocialProfileExtensionField extends Managed_DataObject
     public $__table = 'GNUsocialProfileExtensionField';
     public $id;          // int(11)
     public $systemname;  // varchar(64)
-    public $title;       // varchar(256)
+    public $title;       // varchar(255)
     public $description; // text
-    public $type;        // varchar(256)
+    public $type;        // varchar(255)
+    public $created;     // datetime()   not_null
+    public $modified;    // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    function table()
+    public static function schemaDef()
     {
-        return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'systemname' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'title' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'description' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'type' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
-    }
-    
-    function keys()
-    {
-        return array_keys($this->keyTypes());
+        return array(
+            'fields' => array(
+                'id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique ID for extension field'),
+                'systemname' => array('type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'field systemname'),
+                'title' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'field title'),
+                'description' => array('type' => 'text', 'not null' => true, 'description' => 'field description'),
+                'type' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'field type'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('id'),
+            'indexes' => array(
+                'gnusocialprofileextensionfield_title_idx' => array('title'),
+            ),
+        );
     }
 
     function keyTypes()
index de87447e81d9cfad9b57b4142f8853a8fbd8af4d..4163d4d07707b5bcaf8593ab035645a9ab4b5203 100644 (file)
@@ -39,28 +39,29 @@ class GNUsocialProfileExtensionResponse extends Managed_DataObject
     public $extension_id; // int(11)
     public $profile_id;   // int(11)
     public $value;     // text
+    public $created;      // datetime()   not_null
+    public $modified;     // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    function table()
+    public static function schemaDef()
     {
-        return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'extension_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'value' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
-    }
-    
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
-
-    function keyTypes()
-    {
-        return array('id' => 'K');
-    }
-
-    function sequenceKey()
-    {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique ID for extension response'),
+                'extension_id' => array('type' => 'int', 'not null' => true, 'description' => 'The extension field ID'),
+                'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'Profile id that made the response'),
+                'value' => array('type' => 'text', 'not null' => true, 'description' => 'response entry'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('id'),
+            'foreign keys' => array(
+                'gnusocialprofileextensionresponse_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
+                'gnusocialprofileextensionresponse_extension_id_fkey' => array('GNUsocialProfileExtensionField', array('extension_id' => 'id')),
+            ),
+            'indexes' => array(
+                'gnusocialprofileextensionresponse_extension_id_idx' => array('extension_id'),
+            ),
+        );
     }
 
     static function newResponse($extension_id, $profile_id, $value)
index 468e0eb92e10c84efc796719db4a8a01e336e138..467f384f4d60ccd07743c67323e835e3c15d191a 100644 (file)
@@ -61,69 +61,9 @@ class GroupPrivateMessagePlugin extends Plugin
         $schema = Schema::get();
 
         // For storing user-submitted flags on profiles
-
-        $schema->ensureTable('group_privacy_settings',
-                             array(new ColumnDef('group_id',
-                                                 'integer',
-                                                 null,
-                                                 false,
-                                                 'PRI'),
-                                   new ColumnDef('allow_privacy',
-                                                 'integer'),
-                                   new ColumnDef('allow_sender',
-                                                 'integer'),
-                                   new ColumnDef('created',
-                                                 'datetime'),
-                                   new ColumnDef('modified',
-                                                 'timestamp')));
-
-        $schema->ensureTable('group_message',
-                             array(new ColumnDef('id',
-                                                 'char',
-                                                 36,
-                                                 false,
-                                                 'PRI'),
-                                   new ColumnDef('uri',
-                                                 'varchar',
-                                                 255,
-                                                 false,
-                                                 'UNI'),
-                                   new ColumnDef('from_profile',
-                                                 'integer',
-                                                 null,
-                                                 false,
-                                                 'MUL'),
-                                   new ColumnDef('to_group',
-                                                 'integer',
-                                                 null,
-                                                 false,
-                                                 'MUL'),
-                                   new ColumnDef('content',
-                                                 'text'),
-                                   new ColumnDef('rendered',
-                                                 'text'),
-                                   new ColumnDef('url',
-                                                 'varchar',
-                                                 255,
-                                                 false,
-                                                 'UNI'),
-                                   new ColumnDef('created',
-                                                 'datetime')));
-
-        $schema->ensureTable('group_message_profile',
-                             array(new ColumnDef('to_profile',
-                                                 'integer',
-                                                 null,
-                                                 false,
-                                                 'PRI'),
-                                   new ColumnDef('group_message_id',
-                                                 'char',
-                                                 36,
-                                                 false,
-                                                 'PRI'),
-                                   new ColumnDef('created',
-                                                 'datetime')));
-
+        $schema->ensureTable('group_privacy_settings', Group_privacy_settings::schemaDef());
+        $schema->ensureTable('group_message', Group_message::schemaDef());
+        $schema->ensureTable('group_message_profile', Group_message_profile::schemaDef());
         return true;
     }
 
index 05fcdc5c43aa56cb8b7862a4ad79831f7b941fb6..30b98adecd79dd60258159605276c239deb07c20 100644 (file)
@@ -47,59 +47,44 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
 class Group_message extends Managed_DataObject
 {
     public $__table = 'group_message'; // table name
-    public $id;                        // char(36)  primary_key not_null
+    public $id;                        // varchar(36)  primary_key not_null
     public $uri;                       // varchar(255)
     public $from_profile;              // int
     public $to_group;                  // int
     public $content;
     public $rendered;
     public $url;
-    public $created;
-
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
-    {
-        return array('id' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'from_profile' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'to_group' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'content' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'rendered' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'url' => DB_DATAOBJECT_STR,
-                     'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * DB_DataObject needs to know about keys that the table has, since it
-     * won't appear in StatusNet's own keys list. In most cases, this will
-     * simply reference your keyTypes() function.
-     *
-     * @return array list of key field names
-     */
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
+    public $created;                   // datetime()   not_null
+    public $modified;                  // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    /**
-     * return key definitions for Memcached_DataObject
-     *
-     * @return array associative array of key definitions, field name to type:
-     *         'K' for primary key: for compound keys, add an entry for each component;
-     *         'U' for unique keys: compound keys are not well supported here.
-     */
-    function keyTypes()
+    public static function schemaDef()
     {
-        return array('id' => 'K', 'uri' => 'U');
+        return array(
+            'fields' => array(
+                'id' => array('type' => 'varchar', 'not null' => true, 'length' => 36, 'description' => 'message uuid'),
+                'uri' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'message uri'),
+                'url' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'representation url'),
+                'from_profile' => array('type' => 'int', 'not null' => true, 'description' => 'sending profile ID'),
+                'to_group' => array('type' => 'int', 'not null' => true, 'description' => 'receiving group ID'),
+                'content' => array('type' => 'text', 'not null' => true, 'description' => 'message content'),
+                'rendered' => array('type' => 'text', 'not null' => true, 'description' => 'rendered message'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('id'),
+            'unique keys' => array(
+                'group_message_uri_key' => array('uri'),
+            ),
+            'foreign keys' => array(
+                'group_message_from_profile_fkey' => array('profile', array('from_profile' => 'id')),
+                'group_message_to_group_fkey' => array('user_group', array('to_group' => 'id')),
+            ),
+            'indexes' => array(
+                'group_message_from_profile_idx' => array('from_profile'),
+                'group_message_to_group_idx' => array('to_group'),
+                'group_message_url_idx' => array('url'),
+            ),
+        );
     }
 
     static function send($user, $group, $text)
index 845997f21ff3ae448c43a9620b43316ec299bc4b..5f16dc2eab2916cf6b58236b47fa81ebed82188f 100644 (file)
@@ -48,56 +48,25 @@ class Group_message_profile extends Managed_DataObject
 {
     public $__table = 'group_message_profile'; // table name
     public $to_profile;                        // int
-    public $group_message_id;                  // char(36)  primary_key not_null
-    public $created;
-
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
-    {
-        return array('to_profile' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'group_message_id' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * DB_DataObject needs to know about keys that the table has, since it
-     * won't appear in StatusNet's own keys list. In most cases, this will
-     * simply reference your keyTypes() function.
-     *
-     * @return array list of key field names
-     */
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
-
-    /**
-     * return key definitions for Memcached_DataObject
-     *
-     * @return array associative array of key definitions, field name to type:
-     *         'K' for primary key: for compound keys, add an entry for each component;
-     *         'U' for unique keys: compound keys are not well supported here.
-     */
-    function keyTypes()
-    {
-        return array('to_profile' => 'K', 'group_message_id' => 'K');
-    }
+    public $group_message_id;                  // varchar(36)  primary_key not_null
+    public $created;                           // datetime()   not_null
+    public $modified;                          // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    /**
-     * No sequence keys in this table.
-     */
-    function sequenceKey()
+    public static function schemaDef()
     {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'to_profile' => array('type' => 'int', 'not null' => true, 'description' => 'id of group direct message'),
+                'group_message_id' => array('type' => 'varchar', 'not null' => true, 'length' => 36, 'description' => 'group message uuid'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('to_profile', 'group_message_id'),
+            'foreign keys' => array(
+                'group_message_profile_to_profile_fkey' => array('profile', array('to_profile' => 'id')),
+                'group_message_profile_group_message_id_fkey' => array('group_message', array('group_message_id' => 'id')),
+            ),
+        );
     }
 
     function send($gm, $profile)
index 771c2ec7824fa888ada964769a9bca3254eb0e84..9e983ba3236f74332e372874b1c83fcf4009efed 100644 (file)
@@ -70,58 +70,21 @@ class Group_privacy_settings extends Managed_DataObject
     const MEMBER   = 2;
     const ADMIN    = 4;
 
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
+    public static function schemaDef()
     {
-        return array('group_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'allow_privacy' => DB_DATAOBJECT_INT,
-                     'allow_sender' => DB_DATAOBJECT_INT,
-                     '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);
-
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * DB_DataObject needs to know about keys that the table has, since it
-     * won't appear in StatusNet's own keys list. In most cases, this will
-     * simply reference your keyTypes() function.
-     *
-     * @return array list of key field names
-     */
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
-
-    /**
-     * return key definitions for Memcached_DataObject
-     *
-     * @return array associative array of key definitions, field name to type:
-     *         'K' for primary key: for compound keys, add an entry for each component;
-     *         'U' for unique keys: compound keys are not well supported here.
-     */
-    function keyTypes()
-    {
-        return array('group_id' => 'K');
-    }
-
-    /**
-     * Magic formula for non-autoincrementing integer primary keys
-     *
-     * @return array magic three-false array that stops auto-incrementing.
-     */
-    function sequenceKey()
-    {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group_privacy_settings'),
+                'allow_privacy' => array('type' => 'int', 'not null' => true, 'description' => 'sometimes=-1, never=0, always=1'),
+                'allow_sender' => array('type' => 'int', 'not null' => true, 'description' => 'list of bit-mappy values in source code'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('group_id'),
+            'foreign keys' => array(
+                'group_privacy_settings_group_id_fkey' => array('user_group', array('group_id' => 'id')),
+            ),
+        );
     }
 
     function forGroup($group)
index f74324c186ebb497585ef727ced9e9659029bf53..aeefded4b005413f6aa3aea2608f112c15d926ca 100644 (file)
@@ -160,15 +160,7 @@ class IrcPlugin extends ImPlugin {
         $schema = Schema::get();
 
         // For storing messages while sessions become ready
-        $schema->ensureTable('irc_waiting_message',
-                             array(new ColumnDef('id', 'integer', null,
-                                                 false, 'PRI', null, null, true),
-                                   new ColumnDef('data', 'blob', null, false),
-                                   new ColumnDef('prioritise', 'tinyint', 1, false),
-                                   new ColumnDef('attempts', 'integer', null, false),
-                                   new ColumnDef('created', 'datetime', null, false),
-                                   new ColumnDef('claimed', 'datetime')));
-
+        $schema->ensureTable('irc_waiting_message', Irc_waiting_message::schemaDef());
         return true;
     }
 
index ba8d6bd03dcc6ef2754a5dbedd435636bcf57df1..df7db05b585e6f734a134f4c65315f9a10fec43a 100644 (file)
@@ -12,66 +12,27 @@ class Irc_waiting_message extends Managed_DataObject {
     public $data;                            // blob not_null\r
     public $prioritise;                      // tinyint(1) not_null\r
     public $attempts;                        // int not_null\r
-    public $created;                         // datetime() not_null\r
     public $claimed;                         // datetime()\r
-\r
-    /**\r
-    * return table definition for DB_DataObject\r
-    *\r
-    * DB_DataObject needs to know something about the table to manipulate\r
-    * instances. This method provides all the DB_DataObject needs to know.\r
-    *\r
-    * @return array array of column definitions\r
-    */\r
-    public function table() {\r
-        return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,\r
-                     'data' => DB_DATAOBJECT_BLOB + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,\r
-                     'prioritise' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,\r
-                     'created' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,\r
-                     'claimed' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR);\r
-    }\r
-\r
-    /**\r
-    * return key definitions for DB_DataObject\r
-    *\r
-    * DB_DataObject needs to know about keys that the table has, since it\r
-    * won't appear in StatusNet's own keys list. In most cases, this will\r
-    * simply reference your keyTypes() function.\r
-    *\r
-    * @return array list of key field names\r
-    */\r
-    public function keys() {\r
-        return array_keys($this->keyTypes());\r
-    }\r
-\r
-    /**\r
-    * return key definitions for Memcached_DataObject\r
-    *\r
-    * Our caching system uses the same key definitions, but uses a different\r
-    * method to get them. This key information is used to store and clear\r
-    * cached data, so be sure to list any key that will be used for static\r
-    * lookups.\r
-    *\r
-    * @return array associative array of key definitions, field name to type:\r
-    *         'K' for primary key: for compound keys, add an entry for each component;\r
-    *         'U' for unique keys: compound keys are not well supported here.\r
-    */\r
-    public function keyTypes() {\r
-        return array('id' => 'K');\r
-    }\r
-\r
-    /**\r
-    * Magic formula for non-autoincrementing integer primary keys\r
-    *\r
-    * If a table has a single integer column as its primary key, DB_DataObject\r
-    * assumes that the column is auto-incrementing and makes a sequence table\r
-    * to do this incrementation. Since we don't need this for our class, we\r
-    * overload this method and return the magic formula that DB_DataObject needs.\r
-    *\r
-    * @return array magic three-false array that stops auto-incrementing.\r
-    */\r
-    public function sequenceKey() {\r
-        return array(false, false, false);\r
+    public $created;                         // datetime()   not_null\r
+    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP\r
+\r
+    public static function schemaDef()\r
+    {\r
+        return array(\r
+            'fields' => array(\r
+                'id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique ID for entry'),\r
+                'data' => array('type' => 'blob', 'not null' => true, 'description' => 'data blob'),\r
+                'prioritise' => array('type' => 'int', 'size' => 'tiny', 'description' => 'tinyint priority value'),\r
+                'attempts' => array('type' => 'int', 'not null' => true, 'description' => 'attempts count'),\r
+                'claimed' => array('type' => 'datetime', 'description' => 'date this irc message was claimed'),\r
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),\r
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),\r
+            ),\r
+            'primary key' => array('id'),\r
+            'indexes' => array(\r
+                'irc_waiting_message_prioritise_idx' => array('prioritise'),\r
+            ),\r
+        );\r
     }\r
 \r
     /**\r
index fdef94ce554d4e7ee3e0127927efcaf14c129f6b..38602668b9b5047f2f92edfbb4838a11885a73b5 100644 (file)
@@ -133,14 +133,7 @@ class MsnPlugin extends ImPlugin {
         $schema = Schema::get();\r
 \r
         // For storing messages while sessions become ready\r
-        $schema->ensureTable('msn_waiting_message',\r
-                             array(new ColumnDef('id', 'integer', null,\r
-                                                 false, 'PRI', null, null, true),\r
-                                   new ColumnDef('screenname', 'varchar', 255, false),\r
-                                   new ColumnDef('message', 'text', null, false),\r
-                                   new ColumnDef('created', 'datetime', null, false),\r
-                                   new ColumnDef('claimed', 'datetime')));\r
-\r
+        $schema->ensureTable('msn_waiting_message', Msn_waiting_message::schemaGet());\r
         return true;\r
     }\r
 \r
index 03c03f856ea6e057bca187a6115bff165b092c11..770b1c7df3621cf595e4bf7632e7f82456927125 100644 (file)
@@ -10,66 +10,26 @@ class Msn_waiting_message extends Managed_DataObject {
     public $id;                              // int primary_key not_null auto_increment\r
     public $screenname;                      // varchar(255) not_null\r
     public $message;                         // text not_null\r
-    public $created;                         // datetime() not_null\r
     public $claimed;                         // datetime()\r
+    public $created;                         // datetime()   not_null\r
+    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP\r
 \r
-    /**\r
-    * return table definition for DB_DataObject\r
-    *\r
-    * DB_DataObject needs to know something about the table to manipulate\r
-    * instances. This method provides all the DB_DataObject needs to know.\r
-    *\r
-    * @return array array of column definitions\r
-    */\r
-    public function table() {\r
-        return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,\r
-                     'screenname' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,\r
-                     'message' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,\r
-                     'created' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,\r
-                     'claimed' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR);\r
-    }\r
-\r
-    /**\r
-    * return key definitions for DB_DataObject\r
-    *\r
-    * DB_DataObject needs to know about keys that the table has, since it\r
-    * won't appear in StatusNet's own keys list. In most cases, this will\r
-    * simply reference your keyTypes() function.\r
-    *\r
-    * @return array list of key field names\r
-    */\r
-    public function keys() {\r
-        return array_keys($this->keyTypes());\r
-    }\r
-\r
-    /**\r
-    * return key definitions for Memcached_DataObject\r
-    *\r
-    * Our caching system uses the same key definitions, but uses a different\r
-    * method to get them. This key information is used to store and clear\r
-    * cached data, so be sure to list any key that will be used for static\r
-    * lookups.\r
-    *\r
-    * @return array associative array of key definitions, field name to type:\r
-    *         'K' for primary key: for compound keys, add an entry for each component;\r
-    *         'U' for unique keys: compound keys are not well supported here.\r
-    */\r
-    public function keyTypes() {\r
-        return array('id' => 'K');\r
-    }\r
-\r
-    /**\r
-    * Magic formula for non-autoincrementing integer primary keys\r
-    *\r
-    * If a table has a single integer column as its primary key, DB_DataObject\r
-    * assumes that the column is auto-incrementing and makes a sequence table\r
-    * to do this incrementation. Since we don't need this for our class, we\r
-    * overload this method and return the magic formula that DB_DataObject needs.\r
-    *\r
-    * @return array magic three-false array that stops auto-incrementing.\r
-    */\r
-    function sequenceKey() {\r
-        return array(false, false, false);\r
+    public static function schemaDef()\r
+    {\r
+        return array(\r
+            'fields' => array(\r
+                'id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique ID for entry'),\r
+                'screenname' => array('type' => 'varchar', 'length' => 255, 'description' => 'from screenname'),\r
+                'message' => array('type' => 'text', 'not null' => true, 'description' => 'MSN message text'),\r
+                'claimed' => array('type' => 'datetime', 'description' => 'date this irc message was claimed'),\r
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),\r
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),\r
+            ),\r
+            'primary key' => array('id'),\r
+            'indexes' => array(\r
+                'msn_waiting_message_prioritise_idx' => array('screenname'),\r
+            ),\r
+        );\r
     }\r
 \r
     /**\r
index b2efe8345b9f33b9dbef0fef854238874d84e0b6..d73da51d588848696ea4b7032ab8fe3c73e6b0de 100644 (file)
@@ -71,18 +71,7 @@ class NoticeTitlePlugin extends Plugin
         $schema = Schema::get();
 
         // For storing titles for notices
-
-        $schema->ensureTable('notice_title',
-                             array(new ColumnDef('notice_id',
-                                                 'integer',
-                                                 null,
-                                                 true,
-                                                 'PRI'),
-                                   new ColumnDef('title',
-                                                 'varchar',
-                                                 Notice_title::MAXCHARS,
-                                                 false)));
-
+        $schema->ensureTable('notice_title', Notice_title::schemaDef());
         return true;
     }
 
index fff59c43a1e49c70da396b4e0f40bd2e3c5f708c..610e32fca757bcff1ff39f16f3652c4ad66a578d 100644 (file)
@@ -49,51 +49,25 @@ class Notice_title extends Managed_DataObject
     const MAXCHARS = 255;
 
     public $__table = 'notice_title'; // table name
-    public $notice_id;                         // int(4)  primary_key not_null
+    public $notice_id;                         // int(11)  primary_key not_null
     public $title;                             // varchar(255)
+    public $created;                           // datetime()   not_null
+    public $modified;                          // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
-    {
-        return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'title' => DB_DATAOBJECT_STR);
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * @return array list of key field names
-     */
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
-
-    /**
-     * return key definitions for Memcached_DataObject
-     *
-     * @return array list mapping field names to key types
-     */
-    function keyTypes()
-    {
-        return array('notice_id' => 'K');
-    }
-
-    /**
-     * Magic formula for non-autoincrementing integer primary keys
-     *
-     * @return array magic three-false array that stops auto-incrementing.
-     */
-    function sequenceKey()
+    public static function schemaDef()
     {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id this title relates to'),
+                'title' => array('type' => 'varchar', 'length' => Notice_title::MAXCHARS, 'description' => 'title to notice'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('notice_id'),
+            'foreign keys' => array(
+                'notice_title_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
+            ),
+        );
     }
 
     /**
index 3dfcf6c68acbb97a296c195baae1b2263e950c15..f23311873977b8c477a6f0f4e8d84fff05c0281b 100644 (file)
@@ -554,25 +554,8 @@ class OpenIDPlugin extends Plugin
     function onCheckSchema()
     {
         $schema = Schema::get();
-        $schema->ensureTable('user_openid',
-                             array(new ColumnDef('canonical', 'varchar',
-                                                 '255', false, 'PRI'),
-                                   new ColumnDef('display', 'varchar',
-                                                 '255', false, 'UNI'),
-                                   new ColumnDef('user_id', 'integer',
-                                                 null, false, 'MUL'),
-                                   new ColumnDef('created', 'datetime',
-                                                 null, false),
-                                   new ColumnDef('modified', 'timestamp')));
-        $schema->ensureTable('user_openid_trustroot',
-                             array(new ColumnDef('trustroot', 'varchar',
-                                                 '255', false, 'PRI'),
-                                   new ColumnDef('user_id', 'integer',
-                                                 null, false, 'PRI'),
-                                   new ColumnDef('created', 'datetime',
-                                                 null, false),
-                                   new ColumnDef('modified', 'timestamp')));
-
+        $schema->ensureTable('user_openid', User_openid::schemaDef());
+        $schema->ensureTable('user_openid_trustroot', User_openid_trustroot::schemaDef());
         $schema->ensureTable('user_openid_prefs', User_openid_prefs::schemaDef());
 
         /* These are used by JanRain OpenID library */
index a8ed576114164406d776c7dd43757a986e902368..baff5cd7f96ce8ee24a30c12d2d1cb8f33964d8f 100644 (file)
@@ -22,41 +22,27 @@ class User_openid extends Managed_DataObject
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
-    function table()
+    public static function schemaDef()
     {
-        $db = $this->getDatabaseConnection();
-        $dbtype = $db->phptype; // Database type is stored here. Crazy but true.
-
-        return array('canonical' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'display'   => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'user_id'   => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'created'   => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
-                     'modified'  => ($dbtype == 'mysql' || $dbtype == 'mysqli') ?
-                     DB_DATAOBJECT_MYSQLTIMESTAMP + DB_DATAOBJECT_NOTNULL :
-                     DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME
-                     );
-    }
-
-    /**
-     * List primary and unique keys in this table.
-     * Unique keys used for lookup *MUST* be listed to ensure proper caching.
-     */
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
-
-    function keyTypes()
-    {
-        return array('canonical' => 'K', 'display' => 'U', 'user_id' => 'U');
-    }
-
-    /**
-     * No sequence keys in this table.
-     */
-    function sequenceKey()
-    {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'canonical' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'OpenID canonical string'),
+                'display' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'OpenID display string'),
+                'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'User ID for OpenID owner'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('canonical'),
+            'unique keys' => array(
+                'user_openid_display_key' => array('display'),
+            ),
+            'indexes' => array(
+                'user_openid_user_id_idx' => array('user_id'),
+            ),
+            'foreign keys' => array(
+                'user_openid_user_id_fkey' => array('user', array('user_id' => 'id')),
+            ),
+        );
     }
 
     static function hasOpenID($user_id)
index 04d06c78f6e1e065ebf77419f69fe8535e208c8f..ec09e179e439d3a2704bf70fc82e73ceb7b6933c 100644 (file)
@@ -21,27 +21,16 @@ class User_openid_trustroot extends Managed_DataObject
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
-    function table()
+    public static function schemaDef()
     {
-        $db = $this->getDatabaseConnection();
-        $dbtype = $db->phptype; // Database type is stored here. Crazy but true.
-
-        return array('trustroot' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'user_id'   => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'created'   => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
-                     'modified'  => ($dbtype == 'mysql' || $dbtype == 'mysqli') ?
-                     DB_DATAOBJECT_MYSQLTIMESTAMP + DB_DATAOBJECT_NOTNULL :
-                     DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME
-                     );
-    }
-
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
-
-    function keyTypes()
-    {
-        return array('trustroot' => 'K', 'user_id' => 'K');
+        return array(
+            'fields' => array(
+                'trustroot' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'OpenID trustroot string'),
+                'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'User ID for OpenID trustroot owner'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('trustroot', 'user_id'),
+        );
     }
 }
index 93d990ca77820109a481b198fd3117e144275f60..d6ab7fc0f4b8e8ce8d31264e144330a936d8465c 100644 (file)
@@ -79,12 +79,7 @@ class RegisterThrottlePlugin extends Plugin
         $schema = Schema::get();
 
         // For storing user-submitted flags on profiles
-        $schema->ensureTable('registration_ip',
-                             array(new ColumnDef('user_id', 'integer', null,
-                                                 false, 'PRI'),
-                                   new ColumnDef('ipaddress', 'varchar', 15, false, 'MUL'),
-                                   new ColumnDef('created', 'timestamp', null, false, 'MUL')));
-
+        $schema->ensureTable('registration_ip', Registration_ip::schemaDef());
         return true;
     }
 
index 02b137f987baa1211d485acee12658c96070dc7f..431b6c0562816f49a1cc677d09a6e872353a15c2 100644 (file)
@@ -47,59 +47,27 @@ class Registration_ip extends Managed_DataObject
     public $__table = 'registration_ip';     // table name
     public $user_id;                         // int(4)  primary_key not_null
     public $ipaddress;                       // varchar(15)
-    public $created;                         // timestamp
+    public $created;                         // datetime()   not_null
+    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    /**
-     * return table definition for DB_DataObject
-     *
-     * @return array array of column definitions
-     */
-    function table()
-    {
-        return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'ipaddress' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'created' => DB_DATAOBJECT_MYSQLTIMESTAMP + DB_DATAOBJECT_NOTNULL);
-    }
-
-    /**
-     * 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('user_id' => 'K');
-    }
-
-    /**
-     * 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 $this->keys();
-    }
-
-    /**
-     * Magic formula for non-autoincrementing integer primary keys
-     *
-     * If a table has a single integer column as its primary key, DB_DataObject
-     * assumes that the column is auto-incrementing and makes a sequence table
-     * to do this incrementation. Since we don't need this for our class, we
-     * overload this method and return the magic formula that DB_DataObject needs.
-     *
-     * @return array magic three-false array that stops auto-incrementing.
-     */
-    function sequenceKey()
+    public static function schemaDef()
     {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id this registration relates to'),
+                'ipaddress' => array('type' => 'varchar', 'length' => 45, 'description' => 'IP address, max 45+null in IPv6'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('user_id'),
+            'foreign keys' => array(
+                'registration_ip_user_id_fkey' => array('user', array('user_id' => 'id')),
+            ),
+            'indexes' => array(
+                'registration_ip_ipaddress_idx' => array('ipaddress'),
+                'registration_ip_created_idx' => array('created'),
+            ),
+        );
     }
 
     /**
index 5c34d10bd1664c3377a04b450d1fad36c5f81af4..f2d333bbcb2c0f826d40b36bfda7d32b6c788b38 100644 (file)
@@ -170,23 +170,7 @@ class SamplePlugin extends Plugin
         $schema = Schema::get();
 
         // For storing user-submitted flags on profiles
-
-        $schema->ensureTable('user_greeting_count',
-            array(
-                'fields' => array(
-                    'user_id' => array('type' => 'int', 'not null' => true),
-                    'greeting_count' => array('type' => 'int'),
-                ),
-                'primary key' => array('user_id'),
-                'foreign keys' => array(
-                    // Not all databases will support foreign keys, but even
-                    // when not enforced it's helpful to include these definitions
-                    // as documentation.
-                    'user_greeting_count_user_id_fkey' => array('user', array('user_id' => 'id')),
-                ),
-            )
-        );
-
+        $schema->ensureTable('user_greeting_count', User_greeting_count::schemaDef());
         return true;
     }
 
index 415f710440a509485a9f6dc415c06b5333f537e6..3da00b2d1a8dfa1d61c0344679095297b8dcfe41 100644 (file)
@@ -57,65 +57,23 @@ class User_greeting_count extends Managed_DataObject
     public $__table = 'user_greeting_count'; // table name
     public $user_id;                         // int(4)  primary_key not_null
     public $greeting_count;                  // int(4)
+    public $created;                         // datetime()   not_null
+    public $modified;                        // datetime   not_null default_0000-00-00%2000%3A00%3A00
 
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
-    {
-        return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'greeting_count' => DB_DATAOBJECT_INT);
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * DB_DataObject needs to know about keys that the table has, since it
-     * won't appear in StatusNet's own keys list. In most cases, this will
-     * simply reference your keyTypes() function.
-     *
-     * @return array list of key field names
-     */
-    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. This key information is used to store and clear
-     * cached data, so be sure to list any key that will be used for static
-     * lookups.
-     *
-     * @return array associative array of key definitions, field name to type:
-     *         'K' for primary key: for compound keys, add an entry for each component;
-     *         'U' for unique keys: compound keys are not well supported here.
-     */
-    function keyTypes()
-    {
-        return array('user_id' => 'K');
-    }
-
-    /**
-     * Magic formula for non-autoincrementing integer primary keys
-     *
-     * If a table has a single integer column as its primary key, DB_DataObject
-     * assumes that the column is auto-incrementing and makes a sequence table
-     * to do this incrementation. Since we don't need this for our class, we
-     * overload this method and return the magic formula that DB_DataObject needs.
-     *
-     * @return array magic three-false array that stops auto-incrementing.
-     */
-    function sequenceKey()
+    public static function schemaDef()
     {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
+                'greeting_count' => array('type' => 'int', 'not null' => true, 'description' => 'the greeting count'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('user_id'),
+            'foreign keys' => array(
+                'user_greeting_count_user_id_fkey' => array('user', array('user_id' => 'id')),
+            ),
+        );
     }
 
     /**
index 29b822acd54be6014597c32908d8c75c5505e04d..ae90134db950dcaf1dcc0b84b17ccdcaa338dfc4 100644 (file)
@@ -180,22 +180,8 @@ class SitemapPlugin extends Plugin
     {
         $schema = Schema::get();
 
-        $schema->ensureTable('sitemap_user_count',
-                             array(new ColumnDef('registration_date', 'date', null,
-                                                 true, 'PRI'),
-                                   new ColumnDef('user_count', 'integer'),
-                                   new ColumnDef('created', 'datetime',
-                                                 null, false),
-                                   new ColumnDef('modified', 'timestamp')));
-
-        $schema->ensureTable('sitemap_notice_count',
-                             array(new ColumnDef('notice_date', 'date', null,
-                                                 true, 'PRI'),
-                                   new ColumnDef('notice_count', 'integer'),
-                                   new ColumnDef('created', 'datetime',
-                                                 null, false),
-                                   new ColumnDef('modified', 'timestamp')));
-
+        $schema->ensureTable('sitemap_user_count', Sitemap_user_count::schemaDef());
+        $schema->ensureTable('sitemap_notice_count', Sitemap_notice_count::schemaDef());
         return true;
     }
 
index 46ae65c8388a909df1269c250419cecffe4fb8d8..9e523dfbc7dda8792af18c2c77633cd8d9119e31 100644 (file)
@@ -57,49 +57,20 @@ class Sitemap_notice_count extends Managed_DataObject
 
     public $notice_date;                       // date primary_key not_null
     public $notice_count;                      // int(4)
-    public $created;
-    public $modified;
-
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
-    {
-        return array('notice_date' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_NOTNULL,
-                     'notice_count' => DB_DATAOBJECT_INT,
-                     '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);
-    }
-
-    /**
-     * 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('notice_date' => 'K');
-    }
+    public $created;                           // datetime()   not_null
+    public $modified;                          // datetime   not_null default_0000-00-00%2000%3A00%3A00
 
-    /**
-     * 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()
+    public static function schemaDef()
     {
-        return $this->keys();
+        return array(
+            'fields' => array(
+                'notice_date' => array('type' => 'date', 'not null' => true, 'description' => 'record date'),
+                'notice_count' => array('type' => 'int', 'not null' => true, 'description' => 'the notice count'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('notice_date'),
+        );
     }
 
     static function getAll()
index c085e4de9e26ecf3f52d0c0549ff7384636426dc..865cf246e70de7ec3f445ed4d35471979607ba2e 100644 (file)
@@ -53,55 +53,20 @@ class Sitemap_user_count extends Managed_DataObject
 
     public $registration_date;               // date primary_key not_null
     public $user_count;                      // int(4)
-    public $created;
-    public $modified;
-
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
-    {
-        return array('registration_date' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_NOTNULL,
-                     'user_count' => DB_DATAOBJECT_INT,
-                     '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);
-    }
-
-    /**
-     * 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('registration_date' => 'K');
-    }
-
-    function sequenceKey()
-    {
-        return array(false, false, false);
-    }
-
-    /**
-     * 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 $this->keys();
+    public $created;                         // datetime()   not_null
+    public $modified;                        // datetime   not_null default_0000-00-00%2000%3A00%3A00
+
+    public static function schemaDef()
+    {
+        return array(
+            'fields' => array(
+                'registration_date' => array('type' => 'date', 'not null' => true, 'description' => 'record date'),
+                'user_count' => array('type' => 'int', 'not null' => true, 'description' => 'the user count of the recorded date'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('registration_date'),
+        );
     }
 
     static function getAll()
index 80656ad833fc4a17d6bc2464ff803689431e185d..6f75e3c7da0a42a1b377385b1be062ca1a26cf71 100644 (file)
@@ -57,68 +57,27 @@ class Notice_to_status extends Managed_DataObject
 {
     public $__table = 'notice_to_status'; // table name
     public $notice_id;                    // int(4)  primary_key not_null
-    public $status_id;                    // int(4)
-    public $created;                      // datetime
+    public $status_id;                    // bigint not_null
+    public $created;                      // datetime()   not_null
+    public $modified;                     // datetime   not_null default_0000-00-00%2000%3A00%3A00
 
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
-    {
-        return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'status_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'created'   => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * DB_DataObject needs to know about keys that the table has, since it
-     * won't appear in StatusNet's own keys list. In most cases, this will
-     * simply reference your keyTypes() function.
-     *
-     * @return array list of key field names
-     */
-    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. This key information is used to store and clear
-     * cached data, so be sure to list any key that will be used for static
-     * lookups.
-     *
-     * @return array associative array of key definitions, field name to type:
-     *         'K' for primary key: for compound keys, add an entry for each component;
-     *         'U' for unique keys: compound keys are not well supported here.
-     */
-    function keyTypes()
-    {
-        return array('notice_id' => 'K', 'status_id' => 'U');
-    }
-
-    /**
-     * Magic formula for non-autoincrementing integer primary keys
-     *
-     * If a table has a single integer column as its primary key, DB_DataObject
-     * assumes that the column is auto-incrementing and makes a sequence table
-     * to do this incrementation. Since we don't need this for our class, we
-     * overload this method and return the magic formula that DB_DataObject needs.
-     *
-     * @return array magic three-false array that stops auto-incrementing.
-     */
-    function sequenceKey()
+    public static function schemaDef()
     {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'local notice id'),
+                'status_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'twitter status id'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('notice_id'),
+            'unique keys' => array(
+                'status_id_key' => array('status_id'),
+            ),
+            'foreign keys' => array(
+                'notice_to_status_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
+            ),
+        );
     }
 
     /**
index 6dc8ae8b76545eba81db84ad958de72ee37534ca..1e0f328ad95796d0b83b870fcc6d529a1905ce4a 100644 (file)
@@ -404,28 +404,10 @@ class TwitterBridgePlugin extends Plugin
 
         // For saving the last-synched status of various timelines
         // home_timeline, messages (in), messages (out), ...
-
-        $schema->ensureTable('twitter_synch_status',
-                             array(new ColumnDef('foreign_id', 'bigint', null,
-                                                 false, 'PRI'),
-                                   new ColumnDef('timeline', 'varchar', 255,
-                                                 false, 'PRI'),
-                                   new ColumnDef('last_id', 'bigint', null, // XXX: check for PostgreSQL
-                                                 false),
-                                   new ColumnDef('created', 'datetime', null,
-                                                 false),
-                                   new ColumnDef('modified', 'datetime', null,
-                                                 false)));
+        $schema->ensureTable('twitter_synch_status', Twitter_sync_status::schemaDef());
 
         // For storing user-submitted flags on profiles
-
-        $schema->ensureTable('notice_to_status',
-                             array(new ColumnDef('notice_id', 'integer', null,
-                                                 false, 'PRI'),
-                                   new ColumnDef('status_id', 'bigint', null, // XXX: check for PostgreSQL
-                                                 false, 'UNI'),
-                                   new ColumnDef('created', 'datetime', null,
-                                                 false)));
+        $schema->ensureTable('notice_to_status', Notice_to_status::schemaDef());
 
         return true;
     }
index 6f5147cb6932e94cb6efa7015753bc74808cba6f..9a20536147e3da8be62e0164e6f59808f5c2de8b 100644 (file)
@@ -51,75 +51,24 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
 class Twitter_synch_status extends Managed_DataObject
 {
     public $__table = 'twitter_synch_status'; // table name
-    public $foreign_id;                         // int(4)  primary_key not_null
+    public $foreign_id;                      // bigint primary_key not_null
     public $timeline;                        // varchar(255)  primary_key not_null
     public $last_id;                         // bigint not_null
-    public $created;                         // datetime not_null
-    public $modified;                        // datetime not_null
+    public $created;                         // datetime()   not_null
+    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    /**
-     * 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 array array of column definitions
-     */
-    function table()
+    public static function schemaDef()
     {
-        return array('foreign_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'timeline' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
-                     'last_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     '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
-                     );
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * DB_DataObject needs to know about keys that the table has, since it
-     * won't appear in StatusNet's own keys list. In most cases, this will
-     * simply reference your keyTypes() function.
-     *
-     * @return array list of key field names
-     */
-    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. This key information is used to store and clear
-     * cached data, so be sure to list any key that will be used for static
-     * lookups.
-     *
-     * @return array associative array of key definitions, field name to type:
-     *         'K' for primary key: for compound keys, add an entry for each component;
-     *         'U' for unique keys: compound keys are not well supported here.
-     */
-    function keyTypes()
-    {
-        return array('foreign_id' => 'K',
-                     'timeline' => 'K');
-    }
-
-    /**
-     * Magic formula for non-autoincrementing integer primary keys
-     *
-     * If a table has a single integer column as its primary key, DB_DataObject
-     * assumes that the column is auto-incrementing and makes a sequence table
-     * to do this incrementation. Since we don't need this for our class, we
-     * overload this method and return the magic formula that DB_DataObject needs.
-     *
-     * @return array magic three-false array that stops auto-incrementing.
-     */
-    function sequenceKey()
-    {
-        return array(false, false, false);
+        return array(
+            'fields' => array(
+                'foreign_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'Foreign message ID'),
+                'timeline' => array('type' => 'varchar', 'length' => 255, 'description' => 'timeline name'),
+                'last_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'last id fetched'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('foreign_id', 'timeline'),
+        );
     }
 
     static function getLastId($foreign_id, $timeline)
index 42a8948dffdf4a9ee55634784143ebf6dbac1406..1d8cccd54d5e8707e260015d4ab12efcfb54397b 100644 (file)
@@ -60,17 +60,7 @@ class UserFlagPlugin extends Plugin
         $schema = Schema::get();
 
         // For storing user-submitted flags on profiles
-
-        $schema->ensureTable('user_flag_profile',
-                             array(new ColumnDef('profile_id', 'integer', null,
-                                                 false, 'PRI'),
-                                   new ColumnDef('user_id', 'integer', null,
-                                                 false, 'PRI'),
-                                   new ColumnDef('created', 'datetime', null,
-                                                 false, 'MUL'),
-                                   new ColumnDef('cleared', 'datetime', null,
-                                                 true, 'MUL')));
-
+        $schema->ensureTable('user_flag_profile', User_flag_profile::schemaDef());
         return true;
     }
 
index cd641fc53cc94185fc065e78b77ffc604b506db4..d0cdedccb31df2332a7cd7caa52ee2d715e1c023 100644 (file)
@@ -50,62 +50,31 @@ class User_flag_profile extends Managed_DataObject
     /* the code below is auto generated do not remove the above tag */
 
     public $__table = 'user_flag_profile';               // table name
-    public $profile_id;                      // int(4)  primary_key not_null
-    public $user_id;                         // int(4)  primary_key not_null
-    public $created;                         // datetime   not_null default_0000-00-00%2000%3A00%3A00
-    public $cleared;                         // datetime   not_null default_0000-00-00%2000%3A00%3A00
+    public $profile_id;                      // int(11)  primary_key not_null
+    public $user_id;                         // int(11)  primary_key not_null
+    public $cleared;                         // datetime   default_0000-00-00%2000%3A00%3A00
+    public $created;                         // datetime()   not_null
+    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
-    /**
-     * return table definition for DB_DataObject
-     *
-     * @return array array of column definitions
-     */
-    function table()
+    public static function schemaDef()
     {
         return array(
-                     'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'user_id'    => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'created'    => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
-                     'cleared'    => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME
-                     );
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * @return array of key names
-     */
-    function keys()
-    {
-        return array_keys($this->keyTypes());
-    }
-
-    /**
-     * return key definitions for DB_DataObject
-     *
-     * @return array map of key definitions
-     */
-    function keyTypes()
-    {
-        return array('profile_id' => 'K', 'user_id' => 'K');
-    }
-
-    /**
-     * Magic formula for non-autoincrementing integer primary keys
-     *
-     * If a table has a single integer column as its primary key, DB_DataObject
-     * assumes that the column is auto-incrementing and makes a sequence table
-     * to do this incrementation. Since we don't need this for our class, we
-     * overload this method and return the magic formula that DB_DataObject needs.
-     *
-     * @return array magic three-false array that stops auto-incrementing.
-     */
-    function sequenceKey()
-    {
-        return array(false, false, false);
+            'fields' => array(
+                'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile id flagged'),
+                'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id of the actor'),
+                'cleared' => array('type' => 'datetime', 'description' => 'when flag was removed'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('profile_id', 'user_id'),
+            'indexes' => array(
+                'user_flag_profile_cleared_idx' => array('cleared'),
+                'user_flag_profile_created_idx' => array('created'),
+            ),
+        );
     }
 
     /**