Convert to migrations.
authorJan Schneider <jan@horde.org>
Mon, 13 Dec 2010 18:33:40 +0000 (19:33 +0100)
committerJan Schneider <jan@horde.org>
Thu, 16 Dec 2010 10:23:55 +0000 (11:23 +0100)
vilma/migration/1_vilma_base_tables.php [new file with mode: 0644]
vilma/scripts/sql/vilma.sql [deleted file]

diff --git a/vilma/migration/1_vilma_base_tables.php b/vilma/migration/1_vilma_base_tables.php
new file mode 100644 (file)
index 0000000..8bda289
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+/**
+ * Create Vilma base tables as of 2010-12-13.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you did not
+ * did not receive this file, see http://cvs.horde.org/co.php/vilma/LICENSE.
+ *
+ * @author   Jan Schneider <jan@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @package  Vilma
+ */
+class VilmaBaseTables extends Horde_Db_Migration_Base
+{
+    /**
+     * Upgrade.
+     */
+    public function up()
+    {
+        $tableList = $this->tables();
+
+        if (!in_array('vilma_domains', $tableList)) {
+            $t = $this->createTable('vilma_domains', array('primaryKey' => 'domain_id'));
+            $t->column('domain_id', 'integer', array('null' => false));
+            $t->column('domain_name', 'string', array('limit' => 128, 'null' => false));
+            $t->column('domain_transport', 'string', array('limit' => 128, 'null' => false));
+            $t->column('domain_max_users', 'integer', array('default' => 0, 'null' => false));
+            $t->column('domain_quota', 'integer', array('default' => 0, 'null' => false));
+            $t->column('domain_key', 'string', array('limit' => 64));
+            $t->end();
+
+            $this->addIndex('vilma_domains', 'domain_name', array('unique' => true));
+        }
+
+        if (!in_array('vilma_users', $tableList)) {
+            $t = $this->createTable('vilma_users', array('primaryKey' => 'user_id'));
+            $t->column('user_id', 'integer', array('null' => false));
+            $t->column('user_name', 'string', array('limit' => 255, 'null' => false));
+            $t->column('user_clear', 'string', array('limit' => 255, 'null' => false));
+            $t->column('user_crypt', 'string', array('limit' => 255, 'null' => false));
+            $t->column('user_full_name', 'string', array('limit' => 255, 'null' => false));
+            $t->column('user_uid', 'integer', array('null' => false));
+            $t->column('user_gid', 'integer', array('null' => false));
+            $t->column('user_home_dir', 'string', array('limit' => 255, 'null' => false));
+            $t->column('user_mail_dir', 'string', array('limit' => 255, 'null' => false));
+            $t->column('user_mail_quota', 'integer', array('default' => 0, 'null' => false));
+            $t->column('user_ftp_dir', 'string', array('limit' => 255, 'null' => false));
+            $t->column('user_ftp_quota', 'integer', array('default' => 0, 'null' => false));
+            $t->column('user_enabled', 'integer', array('default' => 1, 'null' => false));
+            $t->end();
+
+            $this->addIndex('vilma_users', 'user_name', array('unique' => true));
+        }
+
+        if (!in_array('vilma_virtuals', $tableList)) {
+            $t = $this->createTable('vilma_virtuals', array('primaryKey' => 'virtual_id'));
+            $t->column('virtual_id', 'integer', array('null' => false));
+            $t->column('virtual_email', 'string', array('limit' => 128, 'null' => false));
+            $t->column('virtual_destination', 'string', array('limit' => 128, 'null' => false));
+            $t->end();
+        }
+    }
+
+    /**
+     * Downgrade to 0
+     */
+    public function down()
+    {
+        $this->dropTable('vilma_domains');
+        $this->dropTable('vilma_users');
+        $this->dropTable('vilma_virtuals');
+    }
+}
diff --git a/vilma/scripts/sql/vilma.sql b/vilma/scripts/sql/vilma.sql
deleted file mode 100644 (file)
index 9dac04c..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-CREATE TABLE vilma_domains (
-  domain_id         INT DEFAULT 0 NOT NULL,
-  domain_name       VARCHAR(128) DEFAULT '' NOT NULL,
-  domain_transport  VARCHAR(128) DEFAULT '' NOT NULL,
-  domain_max_users  INT DEFAULT 0 NOT NULL,
-  domain_quota      INT DEFAULT 0 NOT NULL,
-  domain_key        VARCHAR(64),
---
-  PRIMARY KEY  (domain_id),
-  UNIQUE (domain_name)
-);
-
-CREATE TABLE vilma_users (
-  user_id           INT DEFAULT 0 NOT NULL,
-  user_name         VARCHAR(255) DEFAULT '' NOT NULL,
-  user_clear        VARCHAR(255) DEFAULT '' NOT NULL,
-  user_crypt        VARCHAR(255) DEFAULT '' NOT NULL,
-  user_full_name    VARCHAR(255) DEFAULT '' NOT NULL,
-  user_uid          INT NOT NULL,
-  user_gid          INT NOT NULL,
-  user_home_dir     VARCHAR(255) DEFAULT '' NOT NULL,
-  user_mail_dir     VARCHAR(255) DEFAULT '' NOT NULL,
-  user_mail_quota   INT DEFAULT 0 NOT NULL,
-  user_ftp_dir      VARCHAR(255) DEFAULT NULL,
-  user_ftp_quota    INT DEFAULT NULL,
-  user_enabled      SMALLINT DEFAULT 1 NOT NULL,
---
-  PRIMARY KEY (user_id),
-  UNIQUE (user_name)
-);
-
-CREATE TABLE vilma_virtuals (
-  virtual_id            INT DEFAULT 0 NOT NULL,
-  virtual_email         VARCHAR(128) DEFAULT '' NOT NULL,
-  virtual_destination   VARCHAR(128) DEFAULT '' NOT NULL,
---
-  PRIMARY KEY (virtual_id)
-);