Convert Horde_Perms to migrations.
authorJan Schneider <jan@horde.org>
Fri, 28 Jan 2011 16:56:57 +0000 (17:56 +0100)
committerJan Schneider <jan@horde.org>
Fri, 28 Jan 2011 18:07:05 +0000 (19:07 +0100)
framework/Perms/migration/Horde/Perms/1_horde_perms_base_tables.php [new file with mode: 0644]
framework/Perms/migration/Horde/Perms/2_horde_perms_upgrade_autoincrement.php [new file with mode: 0644]
horde/scripts/sql/horde_perms.mysql.sql [deleted file]
horde/scripts/sql/horde_perms.oci8.sql [deleted file]
horde/scripts/sql/horde_perms.pgsql.sql [deleted file]
horde/scripts/sql/horde_perms.sql [deleted file]
horde/scripts/upgrades/2010-05-24_horde_perms_autoincrement.mysql.sql [deleted file]
horde/scripts/upgrades/2010-05-24_horde_perms_autoincrement.oci8.sql [deleted file]
horde/scripts/upgrades/2010-05-24_horde_perms_autoincrement.pgsql.sql [deleted file]

diff --git a/framework/Perms/migration/Horde/Perms/1_horde_perms_base_tables.php b/framework/Perms/migration/Horde/Perms/1_horde_perms_base_tables.php
new file mode 100644 (file)
index 0000000..a2a8394
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+class HordePermsBaseTables extends Horde_Db_Migration_Base
+{
+    public function up()
+    {
+        if (!in_array('horde_perms', $this->tables())) {
+            $t = $this->createTable('horde_perms', array('primaryKey' => array('perm_id')));
+            $t->column('perm_id', 'integer', array('null' => false));
+            $t->column('perm_name', 'string', array('limit' => 255, 'null' => false));
+            $t->column('perm_parents', 'string', array('limit' => 255, 'null' => false));
+            $t->column('perm_data', 'text');
+            $t->end();
+            $this->addIndex('horde_perms', array('perm_name'), array('unique' => true));
+        }
+    }
+
+    public function down()
+    {
+        $this->dropTable('horde_perms');
+    }
+}
diff --git a/framework/Perms/migration/Horde/Perms/2_horde_perms_upgrade_autoincrement.php b/framework/Perms/migration/Horde/Perms/2_horde_perms_upgrade_autoincrement.php
new file mode 100644 (file)
index 0000000..3516f57
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+class HordePermsUpgradeAutoIncrement extends Horde_Db_Migration_Base
+{
+    public function up()
+    {
+        $this->changeColumn('horde_perms', 'perm_id', 'integer', array('null' => false, 'unsigned' => true, 'default' => null, 'autoincrement' => true));
+    }
+
+    public function down()
+    {
+        $this->changeColumn('horde_perms', 'perm_id', 'integer', array('null' => false));
+    }
+}
\ No newline at end of file
diff --git a/horde/scripts/sql/horde_perms.mysql.sql b/horde/scripts/sql/horde_perms.mysql.sql
deleted file mode 100644 (file)
index eaaf626..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-CREATE TABLE horde_perms (
-    perm_id INT(11) NOT NULL AUTO_INCREMENT,
-    perm_name VARCHAR(255) NOT NULL,
-    perm_parents VARCHAR(255) NOT NULL,
-    perm_data TEXT,
-    PRIMARY KEY (perm_id),
-    UNIQUE KEY perm_name (perm_name)
-);
diff --git a/horde/scripts/sql/horde_perms.oci8.sql b/horde/scripts/sql/horde_perms.oci8.sql
deleted file mode 100644 (file)
index 88b59c5..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-CREATE TABLE horde_perms (
-    perm_id NUMBER(16) NOT NULL,
-    perm_name VARCHAR2(255) NOT NULL UNIQUE,
-    perm_parents VARCHAR2(255) NOT NULL,
-    perm_data CLOB,
-    PRIMARY KEY (perm_id)
-);
-
-CREATE SEQUENCE horde_perms_id_seq;
-CREATE TRIGGER horde_perms_id_trigger
-BEFORE INSERT ON horde_perms
-FOR EACH ROW
-BEGIN
-SELECT horde_perms_id_seq.nextval INTO :new.permid FROM dual;
-END;
\ No newline at end of file
diff --git a/horde/scripts/sql/horde_perms.pgsql.sql b/horde/scripts/sql/horde_perms.pgsql.sql
deleted file mode 100644 (file)
index bf2bee5..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-CREATE TABLE horde_perms (
-    perm_id SERIAL UNIQUE,
-    perm_name VARCHAR(255) NOT NULL UNIQUE,
-    perm_parents VARCHAR(255) NOT NULL,
-    perm_data TEXT,
-    PRIMARY KEY (perm_id)
-);
diff --git a/horde/scripts/sql/horde_perms.sql b/horde/scripts/sql/horde_perms.sql
deleted file mode 100644 (file)
index f2fdeaa..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-CREATE TABLE horde_perms (
-    perm_id INTEGER NOT NULL AUTO_INCREMENT,
-    perm_name VARCHAR(255) NOT NULL,
-    perm_parents VARCHAR(255) NOT NULL,
-    perm_data TEXT,
-    PRIMARY KEY (perm_id)
-);
diff --git a/horde/scripts/upgrades/2010-05-24_horde_perms_autoincrement.mysql.sql b/horde/scripts/upgrades/2010-05-24_horde_perms_autoincrement.mysql.sql
deleted file mode 100644 (file)
index 2f584f2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE horde_perms CHANGE COLUMN perm_id perm_id INT(11) NOT NULL AUTO_INCREMENT;
\ No newline at end of file
diff --git a/horde/scripts/upgrades/2010-05-24_horde_perms_autoincrement.oci8.sql b/horde/scripts/upgrades/2010-05-24_horde_perms_autoincrement.oci8.sql
deleted file mode 100644 (file)
index 8a27c96..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-CREATE SEQUENCE horde_perms_id_seq;
-CREATE TRIGGER horde_perms_id_trigger
-BEFORE INSERT ON horde_perms
-FOR EACH ROW
-BEGIN
-SELECT horde_perms_id_seq.nextval INTO :new.permid FROM dual;
-END;
diff --git a/horde/scripts/upgrades/2010-05-24_horde_perms_autoincrement.pgsql.sql b/horde/scripts/upgrades/2010-05-24_horde_perms_autoincrement.pgsql.sql
deleted file mode 100644 (file)
index 2a2dd49..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-CREATE SEQUENCE horde_perms_id_seq;
-ALTER TABLE horde_perms ALTER COLUMN perm_id SET DEFAULT NEXTVAL('horde_perms_id_seq');