Permalink
Browse files

added PhingAkrabatDbSchemaManager phing task

  • Loading branch information...
Adar Porat
Adar Porat committed Jun 7, 2012
1 parent b801a5f commit 2a801c174c368dafc8a3f47bd88fa3a185b54e68
Showing with 92 additions and 0 deletions.
  1. +15 −0 README.md
  2. +77 −0 phing/tasks/PhingAkrabatDbSchemaManager.php
View
@@ -150,4 +150,19 @@ To get the Zend\Tool provider working:
4. If you want a table prefix, add this to your `application.ini`:
resources.db.table_prefix = "prefix"
+
+
+### Phing Task
+
+1. Define the phing task in the `build.xml`
+
+ <taskdef name="dbmigration" classname="phing.tasks.PhingAkrabatDbSchemaManager" />
+
+2. Setup a phing target with the database options in the `build.xml`
+
+ <target name="database-migration">
+ <dbmigration adapter="mysqli" host="${db.host}" dbname="${db.name}" username="${db.user}" password="${db.pass}" />
+ </target>
+
+3. Run phing using the command line, by `phing database-migration`
@@ -0,0 +1,77 @@
+<?php
+
+/**
+ * Phing class for migrating the database using Akrabat_Db_Schema_Manager
+ *
+ * @see https://github.com/akrabat/Akrabat
+ */
+class PhingAkrabatDbSchemaManager extends Task
+{
+ /**
+ * db adapter
+ * @param string
+ */
+ public function setAdapter($adapter) {
+
+ $this->_adapter = $adapter;
+ }
+
+ /**
+ * db host
+ * @param string
+ */
+ public function setHost($host) {
+
+ $this->_host = $host;
+ }
+
+ /**
+ * db username
+ * @param string
+ */
+ public function setUsername($username) {
+
+ $this->_username = $username;
+ }
+
+ /**
+ * db password
+ * @param string
+ */
+ public function setPassword($password) {
+
+ $this->_password = $password;
+ }
+
+ /**
+ * db name
+ * @param string
+ */
+ public function setDbname($dbname) {
+
+ $this->_dbname = $dbname;
+ }
+
+ public function main()
+ {
+ try {
+
+ $dir = realpath(dirname(__FILE__) . '/../../scripts/migrations');
+ $db = Zend_Db::factory($this->_adapter, array(
+ 'host' => $this->_host,
+ 'username' => $this->_username,
+ 'password' => $this->_password,
+ 'dbname' => $this->_dbname,
+ ));
+
+ $manager = new Akrabat_Db_Schema_Manager($dir, $db);
+ $this->log('Current database schema version is ' . $manager->getCurrentSchemaVersion());
+ $manager->updateTo(null);
+ $this->log('Updated database schema version updated to ' . $manager->getCurrentSchemaVersion());
+ } catch (Zend_Exception $e) {
+ $this->log('Failed executing database migration - ' . $e->getMessage(), Project::MSG_ERR);
+ }
+
+ }
+
+}

0 comments on commit 2a801c1

Please sign in to comment.