Convert Horde_Lock to migrations.
authorJan Schneider <jan@horde.org>
Fri, 28 Jan 2011 16:20:36 +0000 (17:20 +0100)
committerJan Schneider <jan@horde.org>
Fri, 28 Jan 2011 18:07:05 +0000 (19:07 +0100)
framework/Lock/migration/Horde/Lock/1_horde_lock_base_tables.php [new file with mode: 0644]
framework/Lock/migration/Horde/Lock/2_horde_lock_upgrade_column_types.php [new file with mode: 0644]
horde/scripts/sql/horde_locks.sql [deleted file]
horde/scripts/upgrades/2008-05-15-horde_lock_schema.sql [deleted file]
horde/scripts/upgrades/2008-05-16_horde_lock_uuid.sql [deleted file]

diff --git a/framework/Lock/migration/Horde/Lock/1_horde_lock_base_tables.php b/framework/Lock/migration/Horde/Lock/1_horde_lock_base_tables.php
new file mode 100644 (file)
index 0000000..5d4de45
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+class HordeLockBaseTables extends Horde_Db_Migration_Base
+{
+    public function up()
+    {
+        if (!in_array('horde_locks', $this->tables())) {
+            $t = $this->createTable('horde_locks', array('primaryKey' => array('lock_id')));
+            $t->column('lock_id', 'string', array('limit' => 36, 'null' => false));
+            $t->column('lock_owner', 'string', array('limit' => 32, 'null' => false));
+            $t->column('lock_scope', 'string', array('limit' => 32, 'null' => false));
+            $t->column('lock_principal', 'string', array('limit' => 255, 'null' => false));
+            $t->column('lock_origin_timestamp', 'bigint', array('null' => false));
+            $t->column('lock_update_timestamp', 'bigint', array('null' => false));
+            $t->column('lock_expiry_timestamp', 'bigint', array('null' => false));
+            $t->column('lock_type', 'smallint', array('null' => false, 'unsigned' => true));
+            $t->end();
+        }
+    }
+
+    public function down()
+    {
+        $this->dropTable('horde_locks');
+    }
+}
diff --git a/framework/Lock/migration/Horde/Lock/2_horde_lock_upgrade_column_types.php b/framework/Lock/migration/Horde/Lock/2_horde_lock_upgrade_column_types.php
new file mode 100644 (file)
index 0000000..618e14e
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+class HordeLockUpgradeColumnTypes extends Horde_Db_Migration_Base
+{
+    public function up()
+    {
+        $this->changeColumn('horde_locks', 'lock_type', 'tinyint', array('null' => false));
+    }
+
+    public function down()
+    {
+        $this->changeColumn('horde_locks', 'lock_type', 'smallint', array('null' => false, 'unsigned' => true));
+    }
+}
diff --git a/horde/scripts/sql/horde_locks.sql b/horde/scripts/sql/horde_locks.sql
deleted file mode 100644 (file)
index 27263d6..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-CREATE TABLE horde_locks (
-    lock_id                  VARCHAR(36) NOT NULL,
-    lock_owner               VARCHAR(32) NOT NULL,
-    lock_scope               VARCHAR(32) NOT NULL,
-    lock_principal           VARCHAR(255) NOT NULL,
-    lock_origin_timestamp    BIGINT NOT NULL,
-    lock_update_timestamp    BIGINT NOT NULL,
-    lock_expiry_timestamp    BIGINT NOT NULL,
-    lock_type                SMALLINT UNSIGNED NOT NULL,
-
-    PRIMARY KEY (lock_id)
-);
diff --git a/horde/scripts/upgrades/2008-05-15-horde_lock_schema.sql b/horde/scripts/upgrades/2008-05-15-horde_lock_schema.sql
deleted file mode 100644 (file)
index ce034b3..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-DROP TABLE horde_locks;
-
-CREATE TABLE horde_locks (
-    lock_id                  VARCHAR(32) NOT NULL,
-    lock_owner               VARCHAR(32) NOT NULL,
-    lock_scope               VARCHAR(32) NOT NULL,
-    lock_principal           VARCHAR(255) NOT NULL,
-    lock_origin_timestamp    BIGINT NOT NULL,
-    lock_update_timestamp    BIGINT NOT NULL,
-    lock_expiry_timestamp    BIGINT NOT NULL,
-    lock_type                TINYINT NOT NULL,
-
-    PRIMARY KEY (lock_id)
-);
diff --git a/horde/scripts/upgrades/2008-05-16_horde_lock_uuid.sql b/horde/scripts/upgrades/2008-05-16_horde_lock_uuid.sql
deleted file mode 100644 (file)
index 41f45a7..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
--- Allow lock IDs to be UUIDs:
-ALTER TABLE horde_locks CHANGE lock_id lock_id VARCHAR(36);