Migrations for Wicked
authorChuck Hagenbuch <chuck@horde.org>
Sun, 3 Oct 2010 17:38:17 +0000 (13:38 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Sun, 3 Oct 2010 17:41:46 +0000 (13:41 -0400)
wicked/migration/1_wicked_base_tables.php [new file with mode: 0644]
wicked/migration/2_wicked_autoincrement_page_id.php [new file with mode: 0644]
wicked/migration/3_wicked_unsigned_ints.php [new file with mode: 0644]

diff --git a/wicked/migration/1_wicked_base_tables.php b/wicked/migration/1_wicked_base_tables.php
new file mode 100644 (file)
index 0000000..477876e
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+/**
+ * Create Wicked base tables (as of Wicked 1.x).
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @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 (file)
index 0000000..e301e77
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Change page_id column to autoincrement.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @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 (file)
index 0000000..4024765
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Change positive integer columns to unsigned.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @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.
+    }
+}