From 9b7bc2aac1b5e641d7dbe50f8ffd4087b558ccae Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Sun, 3 Oct 2010 13:38:17 -0400 Subject: [PATCH] Migrations for Wicked --- wicked/migration/1_wicked_base_tables.php | 91 ++++++++++++++++++++++ .../migration/2_wicked_autoincrement_page_id.php | 36 +++++++++ wicked/migration/3_wicked_unsigned_ints.php | 52 +++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 wicked/migration/1_wicked_base_tables.php create mode 100644 wicked/migration/2_wicked_autoincrement_page_id.php create mode 100644 wicked/migration/3_wicked_unsigned_ints.php diff --git a/wicked/migration/1_wicked_base_tables.php b/wicked/migration/1_wicked_base_tables.php new file mode 100644 index 000000000..477876eeb --- /dev/null +++ b/wicked/migration/1_wicked_base_tables.php @@ -0,0 +1,91 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Wicked + */ +class WickedBaseTables extends Horde_Db_Migration_Base +{ + /** + * Upgrade. + */ + public function up() + { + $tableList = $this->tables(); + + if (!in_array('wicked_pages', $tableList)) { + $t = $this->createTable('wicked_pages', array('primaryKey' => 'page_id')); + $t->column('page_name', 'string', array('limit' => 100, 'null' => false)); + $t->column('page_text', 'text'); + $t->column('page_hits', 'integer', array('default' => 0)); + $t->column('page_majorversion', 'integer', array('null' => false)); + $t->column('page_minorversion', 'integer', array('null' => false)); + $t->column('version_created', 'integer', array('null' => false)); + $t->column('change_author', 'string'); + $t->column('change_log', 'text'); + $t->end(); + + $this->addIndex('wicked_pages', array('page_name'), array('unique' => true)); + } + + if (!in_array('wicked_history', $tableList)) { + $t = $this->createTable('wicked_history', array('primaryKey' => array('page_id', 'page_majorversion', 'page_minorversion'))); + $t->column('page_id', 'integer', array('null' => false)); + $t->column('page_name', 'string', array('limit' => 100, 'null' => false)); + $t->column('page_text', 'text'); + $t->column('page_majorversion', 'integer', array('null' => false)); + $t->column('page_minorversion', 'integer', array('null' => false)); + $t->column('version_created', 'integer', array('null' => false)); + $t->column('change_author', 'string'); + $t->column('change_log', 'text'); + $t->end(); + $this->addIndex('wicked_history', array('page_name')); + $this->addIndex('wicked_history', array('page_majorversion', 'page_minorversion')); + } + + if (!in_array('wicked_attachments', $tableList)) { + $t = $this->createTable('wicked_attachments', array('primaryKey' => array('page_id', 'attachment_name'))); + $t->column('page_id', 'integer', array('null' => false)); + $t->column('attachment_name', 'string', array('limit' => 100, 'null' => false)); + $t->column('attachment_hits', 'integer', array('default' => 0)); + $t->column('attachment_majorversion', 'integer', array('null' => false)); + $t->column('attachment_minorversion', 'integer', array('null' => false)); + $t->column('attachment_created', 'integer', array('null' => false)); + $t->column('change_author', 'string'); + $t->column('change_log', 'text'); + $t->end(); + } + + if (!in_array('wicked_attachment_history', $tableList)) { + $t = $this->createTable('wicked_attachment_history', array('primaryKey' => array('page_id', 'attachment_name', 'attachment_majorversion', 'attachment_minorversion'))); + $t->column('page_id', 'integer', array('null' => false)); + $t->column('attachment_name', 'string', array('limit' => 100, 'null' => false)); + $t->column('attachment_majorversion', 'integer', array('null' => false)); + $t->column('attachment_minorversion', 'integer', array('null' => false)); + $t->column('attachment_created', 'integer', array('null' => false)); + $t->column('change_author', 'string'); + $t->column('change_log', 'text'); + $t->end(); + $this->addIndex('wicked_attachment_history', array('attachment_majorversion', 'attachment_minorversion')); + } + } + + /** + * Downgrade. + */ + public function down() + { + $this->dropTable('wicked_pages'); + $this->dropTable('wicked_history'); + $this->dropTable('wicked_attachments'); + $this->dropTable('wicked_attachment_history'); + } +} diff --git a/wicked/migration/2_wicked_autoincrement_page_id.php b/wicked/migration/2_wicked_autoincrement_page_id.php new file mode 100644 index 000000000..e301e7729 --- /dev/null +++ b/wicked/migration/2_wicked_autoincrement_page_id.php @@ -0,0 +1,36 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Wicked + */ +class WickedAutoIncrementPageId extends Horde_Db_Migration_Base +{ + /** + * Upgrade. + */ + public function up() + { + $this->changeColumn('wicked_pages', 'page_id', 'integer', array('autoincrement' => true)); + try { + $this->dropTable('wicked_pages_seq'); + } catch (Horde_Db_Exception $e) { + } + } + + /** + * Downgrade. + */ + public function down() + { + $this->changeColumn('wicked_pages', 'page_id', 'integer', array('autoincrement' => false)); + } +} diff --git a/wicked/migration/3_wicked_unsigned_ints.php b/wicked/migration/3_wicked_unsigned_ints.php new file mode 100644 index 000000000..402476536 --- /dev/null +++ b/wicked/migration/3_wicked_unsigned_ints.php @@ -0,0 +1,52 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Wicked + */ +class WickedUnsignedInts extends Horde_Db_Migration_Base +{ + /** + * Upgrade. + */ + public function up() + { + $this->changeColumn('wicked_pages', 'page_id', 'integer', array('auto_increment' => true, 'null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_pages', 'page_hits', 'integer', array('default' => 0, 'unsigned' => true)); + $this->changeColumn('wicked_pages', 'page_majorversion', 'integer', array('null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_pages', 'page_minorversion', 'integer', array('null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_pages', 'version_created', 'integer', array('null' => false, 'unsigned' => true)); + + $this->changeColumn('wicked_history', 'page_id', 'integer', array('null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_history', 'page_majorversion', 'integer', array('null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_history', 'page_minorversion', 'integer', array('null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_history', 'version_created', 'integer', array('null' => false, 'unsigned' => true)); + + $this->changeColumn('wicked_attachments', 'page_id', 'integer', array('null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_attachments', 'attachment_hits', 'integer', array('default' => 0, 'unsigned' => true)); + $this->changeColumn('wicked_attachments', 'attachment_majorversion', 'integer', array('null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_attachments', 'attachment_minorversion', 'integer', array('null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_attachments', 'attachment_created', 'integer', array('null' => false, 'unsigned' => true)); + + $this->changeColumn('wicked_attachment_history', 'page_id', 'integer', array('null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_attachment_history', 'attachment_majorversion', 'integer', array('null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_attachment_history', 'attachment_minorversion', 'integer', array('null' => false, 'unsigned' => true)); + $this->changeColumn('wicked_attachment_history', 'attachment_created', 'integer', array('null' => false, 'unsigned' => true)); + } + + /** + * Downgrade. + */ + public function down() + { + // Don't need to undo these changes, they are non-destructive. + } +} -- 2.11.0