<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -221,7 +221,7 @@ class Migrations{
     * Generate SQL for rename table
     */
     function rename_table( $sTable, $sName ){
-        $sSql = 'ALTER TABLE `'.$sTable.'` RENAME TO `'.$sName.'`;';
+        $sSql = 'ALTER TABLE `'.$this-&gt;getPrefix().$sTable.'` RENAME TO `'.$sName.'`;';
         return $sSql;
     }
         
@@ -237,7 +237,7 @@ class Migrations{
     * Generate SQL for truncate table
     */
     function truncate_table($sTable){
-        $sSql = 'TRUNCATE `'.$sTable.'`;';
+        $sSql = 'TRUNCATE `'.$this-&gt;getPrefix().$sTable.'`;';
         return $sSql;
     }
         
@@ -245,7 +245,7 @@ class Migrations{
     * Generate SQL for add field
     */
     function add_field( $sTable, $aField ){
-        $sSql = 'ALTER TABLE `'.$sTable.'` ADD '.$this-&gt;_buildColumn( key( $aField ), $aField[key($aField)] );
+        $sSql = 'ALTER TABLE `'.$this-&gt;getPrefix().$sTable.'` ADD '.$this-&gt;_buildColumn( key( $aField ), $aField[key($aField)] );
         $sSql = trim( $sSql, &quot;, \n\t&quot; ).';';
         return $sSql;
     }
@@ -254,7 +254,7 @@ class Migrations{
     * Generate SQL for drop field
     */
     function drop_field( $sTable, $column ){
-        $sSql = 'ALTER TABLE `'.$sTable.'` DROP `'.$column.'`;';
+        $sSql = 'ALTER TABLE `'.$this-&gt;getPrefix().$sTable.'` DROP `'.$column.'`;';
         return $sSql;
     }
         
@@ -262,7 +262,7 @@ class Migrations{
     * Generate SQL for alter field
     */
     function alter_field( $sTable, $aField ){
-        $sSql = 'ALTER TABLE `'.$sTable.'` CHANGE `'.key( $aField ).'` '.$this-&gt;_buildColumn( 
+        $sSql = 'ALTER TABLE `'.$this-&gt;getPrefix().$sTable.'` CHANGE `'.key( $aField ).'` '.$this-&gt;_buildColumn( 
                 ( !empty( $aField['name'] ) ? $aField['name'] : key( $aField ) ),
                   $aField[key($aField)] );
         $sSql = trim( $sSql, &quot;, \n\t&quot; );</diff>
      <filename>migrations/migrations.php</filename>
    </modified>
    <modified>
      <diff>@@ -1,107 +1,107 @@
-&lt;?php
-/**
- * Fixtures is a CakePHP shell script that imports data from your YAML files
- *
- * Run 'cake fixtures help' for more info and help on using this script.
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright   Copyright 2008, Georgi Momchilov
- * @link        http://ovalpixels.com
- * @author      Georgi Momchilov
- * @since       CakePHP(tm) v 1.2
- * @license     http://www.opensource.org/licenses/mit-license.php The MIT License
- * 
-*/
-
-uses('file', 'folder');
-App::import('vendor','fixtures');
-
-
-class FixturesShell extends Shell {
-
-    var $sConnection = 'default';
-    var $oFixtures;
-
-    /**
-    * Initializes some paths and checks for the required classes
-    */
-    function startup(){
-        $sPath = APP_PATH .'config' .DS. 'fixtures';
-
-        if(isset($this-&gt;params['p'])) $sPath = $this-&gt;params['p'];
-        if(isset($this-&gt;params['path'])) $sPath = $this-&gt;params['path'];
-        
-        define('FIXTURES_PATH', $sPath );
-        
-        if(isset($this-&gt;params['c'])) $this-&gt;sConnection = $this-&gt;params['c'];
-        if(isset($this-&gt;params['connection'])) $this-&gt;sConnection = $this-&gt;params['connection'];
-        
-        if( !class_exists( 'Fixtures' ) )
-            $this-&gt;error( 'File not found', 'Fixtures class is needed for this shell to run. Could not be found - exiting.' );
-        
-        $this-&gt;oFixtures = new Fixtures( $this-&gt;sConnection );
-        
-        $this-&gt;_welcome();
-    }
-
-    /**
-    * Main method: Imports all fixtures from the fixtures path
-    */
-    function main(){
-        if( !class_exists('Spyc') )
-            $this-&gt;error( 'File not found', 'YAML class is needed for this shell to run. Could not be found - exiting.' );
-        
-        $oFolder = new Folder(FIXTURES_PATH);
-        $aFixtures = $oFolder-&gt;find('.+_fixture\.yml');
-        $oFixtures = new Fixtures( $this-&gt;sConnection );
-        $iCount = 0;
-        foreach( $aFixtures as $sFixture ){
-            $iCount++;
-            if( $oFixtures-&gt;import( FIXTURES_PATH. DS . $sFixture ) !== true ){
-                $this-&gt;error( 'Import failed.', 'Sorry, there was an error inserting the data into your database' );
-            }
-            else{
-                $this-&gt;out( 'Importing '.$sFixture.'...' );
-                $this-&gt;out( '' );
-            }
-        }
-        $this-&gt;out($iCount. ' fixture(s) successfully imported');
-    }
-    
-    /**
-    * Help method
-    */
-    function help(){
-        $this-&gt;hr();
-        $this-&gt;out('');
-        $this-&gt;out('Fixtures help you import your data into your database in a DB engine');
-        $this-&gt;out('agnostic manner.');
-        $this-&gt;out('');
-        $this-&gt;out('Fixture files are YAML files.');
-        $this-&gt;out('');
-        $this-&gt;hr();
-        $this-&gt;out('');
-        $this-&gt;out('COMMAND LINE OPTIONS');
-        $this-&gt;out('');
-        $this-&gt;out('  cake fixtures');
-        $this-&gt;out('    - Imports all fixture files ( .+_fixture\.yml )');
-        $this-&gt;out('');
-        $this-&gt;out('  cake migrate help');
-        $this-&gt;out('    - Displays this Help');
-        $this-&gt;out('');
-        $this-&gt;out(&quot;    append '-c [connection]' to the command if you want to specify the&quot;);
-        $this-&gt;out('    connection to use from database.php. By default it uses &quot;default&quot;');
-        $this-&gt;out('');
-        $this-&gt;out(&quot;    append '-p [path]' to the command if you want to specify the&quot;);
-        $this-&gt;out('    path where the fixture files reside. Default is APP_PATH . \'config\' .DS. \'fixtures\' ');
-        $this-&gt;out('');
-        $this-&gt;out('');
-        $this-&gt;out('For more information and for the latest release of this and others,');
-        $this-&gt;out('go to http://ovalpixels.com');
-        $this-&gt;out('');
-        $this-&gt;hr();
-        $this-&gt;out('');
-    }
+&lt;?php
+/**
+ * Fixtures is a CakePHP shell script that imports data from your YAML files
+ *
+ * Run 'cake fixtures help' for more info and help on using this script.
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright   Copyright 2008, Georgi Momchilov
+ * @link        http://ovalpixels.com
+ * @author      Georgi Momchilov
+ * @since       CakePHP(tm) v 1.2
+ * @license     http://www.opensource.org/licenses/mit-license.php The MIT License
+ * 
+*/
+
+uses('file', 'folder');
+App::import('vendor','fixtures');
+
+
+class FixturesShell extends Shell {
+
+    var $sConnection = 'default';
+    var $oFixtures;
+
+    /**
+    * Initializes some paths and checks for the required classes
+    */
+    function startup(){
+        $sPath = APP_PATH .'config' .DS. 'fixtures';
+
+        if(isset($this-&gt;params['p'])) $sPath = $this-&gt;params['p'];
+        if(isset($this-&gt;params['path'])) $sPath = $this-&gt;params['path'];
+        
+        define('FIXTURES_PATH', $sPath );
+        
+        if(isset($this-&gt;params['c'])) $this-&gt;sConnection = $this-&gt;params['c'];
+        if(isset($this-&gt;params['connection'])) $this-&gt;sConnection = $this-&gt;params['connection'];
+        
+        if( !class_exists( 'Fixtures' ) )
+            $this-&gt;error( 'File not found', 'Fixtures class is needed for this shell to run. Could not be found - exiting.' );
+        
+        $this-&gt;oFixtures = new Fixtures( $this-&gt;sConnection );
+        
+        $this-&gt;_welcome();
+    }
+
+    /**
+    * Main method: Imports all fixtures from the fixtures path
+    */
+    function main(){
+        if( !class_exists('Spyc') )
+            $this-&gt;error( 'File not found', 'YAML class is needed for this shell to run. Could not be found - exiting.' );
+        
+        $oFolder = new Folder(FIXTURES_PATH);
+        $aFixtures = $oFolder-&gt;find('.+_fixture\.yml');
+        $oFixtures = new Fixtures( $this-&gt;sConnection );
+        $iCount = 0;
+        foreach( $aFixtures as $sFixture ){
+            $iCount++;
+            if( $oFixtures-&gt;import( FIXTURES_PATH. DS . $sFixture ) !== true ){
+                $this-&gt;error( 'Import failed.', 'Sorry, there was an error inserting the data into your database' );
+            }
+            else{
+                $this-&gt;out( 'Importing '.$sFixture.'...' );
+                $this-&gt;out( '' );
+            }
+        }
+        $this-&gt;out($iCount. ' fixture(s) successfully imported');
+    }
+    
+    /**
+    * Help method
+    */
+    function help(){
+        $this-&gt;hr();
+        $this-&gt;out('');
+        $this-&gt;out('Fixtures help you import your data into your database in a DB engine');
+        $this-&gt;out('agnostic manner.');
+        $this-&gt;out('');
+        $this-&gt;out('Fixture files are YAML files.');
+        $this-&gt;out('');
+        $this-&gt;hr();
+        $this-&gt;out('');
+        $this-&gt;out('COMMAND LINE OPTIONS');
+        $this-&gt;out('');
+        $this-&gt;out('  cake fixtures');
+        $this-&gt;out('    - Imports all fixture files ( .+_fixture\.yml )');
+        $this-&gt;out('');
+        $this-&gt;out('  cake migrate help');
+        $this-&gt;out('    - Displays this Help');
+        $this-&gt;out('');
+        $this-&gt;out(&quot;    append '-c [connection]' to the command if you want to specify the&quot;);
+        $this-&gt;out('    connection to use from database.php. By default it uses &quot;default&quot;');
+        $this-&gt;out('');
+        $this-&gt;out(&quot;    append '-p [path]' to the command if you want to specify the&quot;);
+        $this-&gt;out('    path where the fixture files reside. Default is APP_PATH . \'config\' .DS. \'fixtures\' ');
+        $this-&gt;out('');
+        $this-&gt;out('');
+        $this-&gt;out('For more information and for the latest release of this and others,');
+        $this-&gt;out('go to http://ovalpixels.com');
+        $this-&gt;out('');
+        $this-&gt;hr();
+        $this-&gt;out('');
+    }
 }
\ No newline at end of file</diff>
      <filename>shells/fixtures.php</filename>
    </modified>
    <modified>
      <diff>@@ -1,480 +1,480 @@
-&lt;?php
-/**
- * Migrations is a CakePHP shell script that runs your database migrations to the specified schema
- * version. If no version is specified, migrations are run to the latest version.
- *
- * Run 'cake migrate help' for more info and help on using this script.
- *
- * Heavily based on Joel Moss' Migrations shell ( http://joelmoss.info ) but uses cake's internal functions instead of PEAR::MDB2 
- * and doesn't have some methods I found unnecessary.
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright   Copyright 2008, Georgi Momchilov
- * @link        http://ovalpixels.com
- * @author      Georgi Momchilov
- * @since       CakePHP(tm) v 1.2
- * @license     http://www.opensource.org/licenses/mit-license.php The MIT License
- * 
-*/
-
-uses('file', 'folder');
-App::import('vendor','spyc');
-App::import('vendor','migrations');
-
-
-class MigrateShell extends Shell {
-
-    var $sConnection = 'default';
-    var $aMigrations;
-    var $oMigrations;
-
-    /**
-    * Initializes some paths and checks for the required classes
-    */
-    function startup(){
-        define('MIGRATIONS_PATH', APP_PATH .'config' .DS. 'migrations');
-
-        if(isset($this-&gt;params['c'])) $this-&gt;sConnection = $this-&gt;params['c'];
-        if(isset($this-&gt;params['connection'])) $this-&gt;sConnection = $this-&gt;params['connection'];
-        
-        if( !class_exists( 'Migrations' ) )
-            $this-&gt;error( 'File not found', 'Migrations class is needed for this shell to run. Could not be found - exiting.' );
-        
-        $this-&gt;oMigrations = new Migrations( $this-&gt;sConnection );
-        
-        $this-&gt;_welcome();
-        $this-&gt;out('App : '. APP_DIR);
-        $this-&gt;out('Path: '. ROOT . DS . APP_DIR);
-        $this-&gt;_getMigrationVersion();
-        $this-&gt;out('');
-        $this-&gt;out('Current schema version: '.$this-&gt;iCurrent_version);
-        $this-&gt;out('');
-        $this-&gt;_getMigrations();
-    }
-
-    /**
-    * Main method: migrates to the latest version.
-    */
-    function main(){
-        if( !isset( $this-&gt;params['v'] ) ){
-            $this-&gt;_migrate_to_version($this-&gt;iMigration_count);
-        }
-        else{
-            $iTo_v = intval( $this-&gt;params['v'] );
-            if( $iTo_v &gt; $this-&gt;iMigration_count || $iTo_v &lt; 0 ){
-                $this-&gt;out('  ** Version number entered ('.$iTo_v.') does not exist. **');
-                $this-&gt;out('');
-            }
-            else{
-                $this-&gt;_migrate_to_version( $iTo_v );
-            }
-        }
-        $this-&gt;out('Migrations completed.');
-        $this-&gt;out('');
-        $this-&gt;hr();
-        $this-&gt;out('');
-        exit;
-    }
-    
-    /**
-    * Generates an YAML file from the current DB schema
-    */
-    function generate(){
-        $this-&gt;out('Generating full schema YAML file schema.yml...');
-        $this-&gt;out('');
-        $this-&gt;hr();
-        $this-&gt;out('');
-        $oFile = new File( MIGRATIONS_PATH . DS . 'schema.yml', true );
-        if( !$oFile-&gt;writable() ){
-            $this-&gt;out( '' );
-            $this-&gt;out( 'Your migrations folder is not writable - I could not write the file schema.yml . Please check your permissions.' );
-            $this-&gt;out('');
-            exit;
-        }
-        $oFile-&gt;write( $this-&gt;oMigrations-&gt;generate() );
-        $this-&gt;out( 'Schema file ( schema.yml ) successfully written!' );
-        $this-&gt;out('');
-    }
-
-    /**
-    * Migrates down to the previous version
-    */
-    function down(){
-        $this-&gt;iTo_version = ($this-&gt;iCurrent_version === 0) ? $this-&gt;iCurrent_version : $this-&gt;iCurrent_version - 1;
-        $this-&gt;_run();
-        $this-&gt;out('Migrations completed.');
-        $this-&gt;out('');
-        $this-&gt;hr();
-        $this-&gt;out('');
-        exit;
-    }
-
-    /**
-    * Migrates up to the next version
-    */
-    function up(){
-        $this-&gt;iTo_version = ($this-&gt;iCurrent_version == $this-&gt;iMigration_count) ? $this-&gt;iCurrent_version : $this-&gt;iCurrent_version + 1;
-        $this-&gt;_run();
-        $this-&gt;out('Migrations completed.');
-        $this-&gt;out('');
-        $this-&gt;hr();
-        $this-&gt;out('');
-        exit;
-    }
-
-    /**
-    * Reset migration version to zero without running migrations up or down and drops all tables
-    */
-    function reset(){
-        $this-&gt;iTo_version = 0;
-        $aTables = $this-&gt;oMigrations-&gt;oDb-&gt;listSources();
-        foreach( $aTables as $sTable )if( $sTable !== 'schema_info' ){
-            $this-&gt;oMigrations-&gt;oDb-&gt;query( $this-&gt;oMigrations-&gt;drop_table( $sTable ) );
-        }
-        $this-&gt;_updateVersion(0);
-        $this-&gt;hr();
-        $this-&gt;out('');
-        $this-&gt;out('  ** Schema reset **');
-        $this-&gt;out('');
-        $this-&gt;out('');
-        $this-&gt;out('Migrations completed.');
-        $this-&gt;out('');
-        $this-&gt;hr();
-        $this-&gt;out('');
-        exit;
-    }
-
-    /**
-    * Runs all migrations from the current version down and back up to the latest version.
-    */
-    function all(){
-        if( $this-&gt;iCurrent_version &gt; 0 )
-            $this-&gt;_migrate_to_version(0);
-        $this-&gt;_migrate_to_version($this-&gt;iMigration_count);
-        $this-&gt;out('');
-        $this-&gt;hr();
-        $this-&gt;out('');
-        $this-&gt;out('All migrations completed.');
-        $this-&gt;out('');
-        $this-&gt;hr();
-        $this-&gt;out('');
-        exit;
-    }
-    
-    /**
-    * Modifies the out method for prettier formatting
-    *
-    * @param string $sString String to output.
-    * @param boolean $bNewline If true, the outputs gets an added newline.
-    */
-    function out($sString, $bNewline = true) {
-        return parent::out(&quot;  &quot;.$sString, $bNewline);
-    }
-    
-    /**
-    * Help method
-    */
-    function help(){
-        $this-&gt;hr();
-        $this-&gt;out('');
-        $this-&gt;out('Database migrations is a version control system for your database,');
-        $this-&gt;out('allowing you to migrate your database schema between versions.');
-        $this-&gt;out('');
-        $this-&gt;out('Each version is depicted by a migration file written in YAML and must');
-        $this-&gt;out('include an UP and DOWN section. The UP section is parsed and run when');
-        $this-&gt;out('migrating up and vice versa.');
-        $this-&gt;out('');
-        $this-&gt;hr();
-        $this-&gt;out('');
-        $this-&gt;out('COMMAND LINE OPTIONS');
-        $this-&gt;out('');
-        $this-&gt;out('  cake migrate');
-        $this-&gt;out('    - Migrates to the latest version (the last migration file)');
-        $this-&gt;out('');
-        $this-&gt;out('  cake migrate -v [version number]');
-        $this-&gt;out('    - Migrates to the version specified [version number]');
-        $this-&gt;out('');
-        $this-&gt;out('  cake migrate reset');
-        $this-&gt;out('    - Resets the current version to 0 and drops all tables.');
-        $this-&gt;out('');
-        $this-&gt;out('  cake migrate all');
-        $this-&gt;out('    - Migrates down to 0 and back up to the latest version');
-        $this-&gt;out('');
-        $this-&gt;out('  cake migrate down');
-        $this-&gt;out('    - Migrates down to the previous current version');
-        $this-&gt;out('');
-        $this-&gt;out('  cake migrate up');
-        $this-&gt;out('    - Migrates up from the current to the next version');
-        $this-&gt;out('');
-        $this-&gt;out('  cake migrate generate');
-        $this-&gt;out('    - Write an YAML file out of your current DB schema');
-        $this-&gt;out('');
-        $this-&gt;out('  cake migrate help');
-        $this-&gt;out('    - Displays this Help');
-        $this-&gt;out('');
-        $this-&gt;out(&quot;    append '-c [connection]' to the command if you want to specify the&quot;);
-        $this-&gt;out('    connection to use from database.php. By default it uses &quot;default&quot;');
-        $this-&gt;out('');
-        $this-&gt;out('');
-        $this-&gt;out('For more information and for the latest release of this and others,');
-        $this-&gt;out('go to http://ovalpixels.com');
-        $this-&gt;out('');
-        $this-&gt;hr();
-        $this-&gt;out('');
-    }
-
-    /**
-    * Aliases for the help method
-    */
-    function h() { $this-&gt;help(); }
-
-    /**
-    * Private method used to alter the destination version and run the migrating method ( _run )
-    *
-    * @access protected
-    * @param integer #iNewVersion The destination version
-    */
-    function _migrate_to_version( $iNew_version ){
-            if( !isset( $this-&gt;iTo_version ) || $iNew_version != $this-&gt;iTo_version ){
-                $this-&gt;iTo_version = $iNew_version;
-                $this-&gt;_run();
-            }
-    }
-
-    /**
-    * Protected method which does all the dirty work. Compares the destination and current version of the schema and runs the respective UPs or DOWNs
-    */
-    function _run(){
-        $this-&gt;hr();
-
-        if( $this-&gt;iCurrent_version == $this-&gt;iTo_version ){
-            $this-&gt;out('');
-            $this-&gt;out('  ** Migration version is the same as the current version **');
-            $this-&gt;out('');
-            $this-&gt;hr();
-            $this-&gt;out('');
-            exit;    
-        }
-        if ($this-&gt;iMigration_count === 0){
-            $this-&gt;out('');
-            $this-&gt;out('  ** No migrations found **');
-            $this-&gt;out('');
-            $this-&gt;hr();
-            $this-&gt;out('');
-            exit;
-        }
-        $iNew_version = $this-&gt;iTo_version;
-
-        if (!is_numeric($iNew_version)){
-            $this-&gt;out('');
-            $this-&gt;out('  ** Migration version number ('.$iNew_version.') is invalid. **');
-            $this-&gt;out('');
-            $this-&gt;hr();
-            $this-&gt;out('');
-            exit;
-        }
-        if ($iNew_version &gt; $this-&gt;iMigration_count){
-            $this-&gt;out('');
-            $this-&gt;out('  ** Version number entered ('.$iNew_version.') does not exist. **');
-            $this-&gt;out('');
-            $this-&gt;hr();
-            $this-&gt;out('');
-            exit;
-        }
-
-        $sDirection = ($iNew_version &lt; $this-&gt;iCurrent_version) ? 'down' : 'up';
-        if ($sDirection == 'down') usort($this-&gt;aMigrations, array($this, '_downMigrations'));
-        elseif ($sDirection == 'up') usort($this-&gt;aMigrations, array($this, '_upMigrations'));
-
-        $this-&gt;out('');
-        $this-&gt;out(&quot;Migrating database $sDirection from version {$this-&gt;iCurrent_version} to $iNew_version ...&quot;);
-        $this-&gt;out('');
-
-        foreach($this-&gt;aMigrations as $sMigration_name){
-            preg_match(&quot;/^([0-9]+)\_(.+)(\.yml)$/&quot;, $sMigration_name, $aMatch);
-            $iNum = $this-&gt;_versionIt($aMatch[1]);
-            $sName = Inflector::humanize($aMatch[2]);
-
-            if ($sDirection == 'up'){
-                if ($iNum &lt;= $this-&gt;iCurrent_version) continue;
-                if ($iNum &gt; $iNew_version) break;
-            }
-            elseif( $sDirection == 'down' ){
-                if ($iNum &gt; $this-&gt;iCurrent_version) continue;
-                if ($iNum == $iNew_version) break;
-            }
-
-            $this-&gt;out(&quot;  [$iNum] $sName ...&quot;);
-
-            $rRes = $this-&gt;_loadMigration(MIGRATIONS_PATH .DS. $sMigration_name, $sDirection);
-            if ($rRes === true){
-                $this-&gt;out('');
-                if ($sDirection == 'up'){
-                    $this-&gt;_updateVersion( 'version+1' );
-                }
-                else{
-                    $this-&gt;_updateVersion( 'version-1' );
-                }
-            }
-            elseif( is_numeric( $rRes ) &amp;&amp; $rRes &lt; 1 ){
-                $this-&gt;out('Generic error: '.$rRes );
-                $this-&gt;hr();
-                exit;
-            }
-            else{
-                $this-&gt;out(&quot;  ERROR: &quot;);
-                foreach( $rRes as $aErr ){
-                    $this-&gt;out('Query: '.$aErr['sql']);
-                    $this-&gt;out('');
-                    $this-&gt;out('Error: '.$aErr['error']);
-                }
-                $this-&gt;hr();
-                exit;
-            }
-        }
-    }
-    
-    /**
-    * Loads the file with the YAML migration schema and runs the generates the SQL script for the specified direction
-    *
-    * @access protected
-    * @param string $sFile Path to the file
-    * @param string $sFile Path to the file
-    * @return mixed False on failure and a SQL command on success
-    */
-    function _loadMigration( $sFile, $sDirection ){
-        if( !$bLoad = $this-&gt;oMigrations-&gt;load($sFile) ){
-            return $bLoad;
-        }
-        else
-            return $this-&gt;oMigrations-&gt;{$sDirection}();
-    }
-
-    /**
-    * An internal sort method - used with usort(). Sorts from top to bottom
-    *
-    * @access protected
-    * @param string $sA Name of a migration ( with the number in front )
-    * @param string $sB Name of a migration ( with the number in front )
-    * @return int &lt; = &gt;
-    */
-    function _upMigrations($sA, $sB){
-        list($aStr) = explode('_', $sA);
-        list($bStr) = explode('_', $sB);
-        $aNum = (int)$aStr;
-        $bNum = (int)$bStr;
-        if ($aNum == $bNum){
-            return 0;
-        }
-        return ($aNum &gt; $bNum) ? 1 : -1;
-    }
-
-    /**
-    * An internal sort method - used with usort(). Sorts from bottom to top
-    *
-    * @access protected
-    * @param string $sA Name of a migration ( with the number in front )
-    * @param string $sB Name of a migration ( with the number in front )
-    * @return int &lt; = &gt;
-    */
-    function _downMigrations($sA, $sB){
-        list($aStr) = explode('_', $sA);
-        list($bStr) = explode('_', $sB);
-        $aNum = (int)$aStr;
-        $bNum = (int)$bStr;
-        if ($aNum == $bNum) {
-            return 0;
-        }
-        return ($aNum &gt; $bNum) ? -1 : 1;
-    }
-
-    /**
-    * Gets the current schema version from the DB. If schema_info doesn't exist - it tries to create it.
-    *
-    * @access protected
-    * @return int Current schema version
-    */
-    function _getMigrationVersion(){
-        //load tables and see if schema_info already exists. If not, create it
-        $sTables = $this-&gt;oMigrations-&gt;oDb-&gt;listSources();
-        if( !in_array( 'schema_info', $sTables ) ){
-            $this-&gt;oMigrations-&gt;oDb-&gt;query( 
-                $this-&gt;oMigrations-&gt;create_table(
-                    'schema_info', 
-                    array(  0 =&gt; 'no_id',
-                            1 =&gt; 'no_dates', 
-                            'version' =&gt; 
-                                array( 'type' =&gt; 'int', 'length' =&gt; 3, 'default' =&gt; '0' ) ) 
-                 )
-            );
-            //feed it with some data
-            App::import('model');
-            $oTemp_model = new Model( false, 'schema_info' );
-            $oTemp_model-&gt;saveField( 'version', '0' );
-            $this-&gt;iCurrent_version = 0;
-
-        }
-        else{
-            App::import('model');
-            $oTemp_model = new Model( false, 'schema_info' );
-            $this-&gt;iCurrent_version = $oTemp_model-&gt;field( 'version' );
-        }
-    }
-
-    /**
-    * Update the current shchema version in the database
-    *
-    * @access protected
-    * @param mixed $sVersion The new schema version. Can be either an integer ( 1, 2, 3 ) or an expression ( version + 1 )
-    * @return void
-    */
-    function _updateVersion($sVersion){
-        App::import('model');
-        $oTemp_model = new Model( false, 'schema_info' );
-        $oTemp_model-&gt;updateAll( array( 'version' =&gt; $sVersion ) );
-        $this-&gt;_getMigrationVersion();
-    }
-    
-    /**
-    * Loads the migration yaml files into an array ( self::aMigrations )
-    *
-    * @access protected
-    * @return void
-    */
-    function _getMigrations(){
-        $oFolder = new Folder(MIGRATIONS_PATH, true, 0777);
-        $this-&gt;aMigrations = $oFolder-&gt;find(&quot;[0-9]+_.+\.yml&quot;);
-        usort($this-&gt;aMigrations, array($this, '_upMigrations'));
-        $this-&gt;iMigration_count = count($this-&gt;aMigrations);
-    }
-
-    /**
-    * Converts migration number to a minimum three digit number.
-    *
-    * @param $iNum The number to convert
-    * @return integer The converted three digit number
-    */
-    function _versionIt($iNum){
-        switch (strlen($iNum)){
-            case 1:
-                return '00'.$iNum;
-            case 2:
-                return '0'.$iNum;
-            default:
-                return $iNum;
-        }
-    }
-    
-    /**
-    * Welcome method
-    */
-    function _welcome(){
-        $this-&gt;out('');
-        $this-&gt;out(' __  __  _  _  __     ___     __   __   __  ___    __  _  _  __ ');
-        $this-&gt;out('|   |__| |_/  |__    | | | | | _  |__| |__|  |  | |  | |\ | |__ ');
-        $this-&gt;out('|__ |  | | \_ |__    | | | | |__| | \_ |  |  |  | |__| | \|  __|');
-        $this-&gt;out('');
-    }
+&lt;?php
+/**
+ * Migrations is a CakePHP shell script that runs your database migrations to the specified schema
+ * version. If no version is specified, migrations are run to the latest version.
+ *
+ * Run 'cake migrate help' for more info and help on using this script.
+ *
+ * Heavily based on Joel Moss' Migrations shell ( http://joelmoss.info ) but uses cake's internal functions instead of PEAR::MDB2 
+ * and doesn't have some methods I found unnecessary.
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright   Copyright 2008, Georgi Momchilov
+ * @link        http://ovalpixels.com
+ * @author      Georgi Momchilov
+ * @since       CakePHP(tm) v 1.2
+ * @license     http://www.opensource.org/licenses/mit-license.php The MIT License
+ * 
+*/
+
+uses('file', 'folder');
+App::import('vendor','spyc');
+App::import('vendor','migrations');
+
+
+class MigrateShell extends Shell {
+
+    var $sConnection = 'default';
+    var $aMigrations;
+    var $oMigrations;
+
+    /**
+    * Initializes some paths and checks for the required classes
+    */
+    function startup(){
+        define('MIGRATIONS_PATH', APP_PATH .'config' .DS. 'migrations');
+
+        if(isset($this-&gt;params['c'])) $this-&gt;sConnection = $this-&gt;params['c'];
+        if(isset($this-&gt;params['connection'])) $this-&gt;sConnection = $this-&gt;params['connection'];
+        
+        if( !class_exists( 'Migrations' ) )
+            $this-&gt;error( 'File not found', 'Migrations class is needed for this shell to run. Could not be found - exiting.' );
+        
+        $this-&gt;oMigrations = new Migrations( $this-&gt;sConnection );
+        
+        $this-&gt;_welcome();
+        $this-&gt;out('App : '. APP_DIR);
+        $this-&gt;out('Path: '. ROOT . DS . APP_DIR);
+        $this-&gt;_getMigrationVersion();
+        $this-&gt;out('');
+        $this-&gt;out('Current schema version: '.$this-&gt;iCurrent_version);
+        $this-&gt;out('');
+        $this-&gt;_getMigrations();
+    }
+
+    /**
+    * Main method: migrates to the latest version.
+    */
+    function main(){
+        if( !isset( $this-&gt;params['v'] ) ){
+            $this-&gt;_migrate_to_version($this-&gt;iMigration_count);
+        }
+        else{
+            $iTo_v = intval( $this-&gt;params['v'] );
+            if( $iTo_v &gt; $this-&gt;iMigration_count || $iTo_v &lt; 0 ){
+                $this-&gt;out('  ** Version number entered ('.$iTo_v.') does not exist. **');
+                $this-&gt;out('');
+            }
+            else{
+                $this-&gt;_migrate_to_version( $iTo_v );
+            }
+        }
+        $this-&gt;out('Migrations completed.');
+        $this-&gt;out('');
+        $this-&gt;hr();
+        $this-&gt;out('');
+        exit;
+    }
+    
+    /**
+    * Generates an YAML file from the current DB schema
+    */
+    function generate(){
+        $this-&gt;out('Generating full schema YAML file schema.yml...');
+        $this-&gt;out('');
+        $this-&gt;hr();
+        $this-&gt;out('');
+        $oFile = new File( MIGRATIONS_PATH . DS . 'schema.yml', true );
+        if( !$oFile-&gt;writable() ){
+            $this-&gt;out( '' );
+            $this-&gt;out( 'Your migrations folder is not writable - I could not write the file schema.yml . Please check your permissions.' );
+            $this-&gt;out('');
+            exit;
+        }
+        $oFile-&gt;write( $this-&gt;oMigrations-&gt;generate() );
+        $this-&gt;out( 'Schema file ( schema.yml ) successfully written!' );
+        $this-&gt;out('');
+    }
+
+    /**
+    * Migrates down to the previous version
+    */
+    function down(){
+        $this-&gt;iTo_version = ($this-&gt;iCurrent_version === 0) ? $this-&gt;iCurrent_version : $this-&gt;iCurrent_version - 1;
+        $this-&gt;_run();
+        $this-&gt;out('Migrations completed.');
+        $this-&gt;out('');
+        $this-&gt;hr();
+        $this-&gt;out('');
+        exit;
+    }
+
+    /**
+    * Migrates up to the next version
+    */
+    function up(){
+        $this-&gt;iTo_version = ($this-&gt;iCurrent_version == $this-&gt;iMigration_count) ? $this-&gt;iCurrent_version : $this-&gt;iCurrent_version + 1;
+        $this-&gt;_run();
+        $this-&gt;out('Migrations completed.');
+        $this-&gt;out('');
+        $this-&gt;hr();
+        $this-&gt;out('');
+        exit;
+    }
+
+    /**
+    * Reset migration version to zero without running migrations up or down and drops all tables
+    */
+    function reset(){
+        $this-&gt;iTo_version = 0;
+        $aTables = $this-&gt;oMigrations-&gt;oDb-&gt;listSources();
+        foreach( $aTables as $sTable )if( $sTable !== 'schema_info' ){
+            $this-&gt;oMigrations-&gt;oDb-&gt;query( $this-&gt;oMigrations-&gt;drop_table( $sTable ) );
+        }
+        $this-&gt;_updateVersion(0);
+        $this-&gt;hr();
+        $this-&gt;out('');
+        $this-&gt;out('  ** Schema reset **');
+        $this-&gt;out('');
+        $this-&gt;out('');
+        $this-&gt;out('Migrations completed.');
+        $this-&gt;out('');
+        $this-&gt;hr();
+        $this-&gt;out('');
+        exit;
+    }
+
+    /**
+    * Runs all migrations from the current version down and back up to the latest version.
+    */
+    function all(){
+        if( $this-&gt;iCurrent_version &gt; 0 )
+            $this-&gt;_migrate_to_version(0);
+        $this-&gt;_migrate_to_version($this-&gt;iMigration_count);
+        $this-&gt;out('');
+        $this-&gt;hr();
+        $this-&gt;out('');
+        $this-&gt;out('All migrations completed.');
+        $this-&gt;out('');
+        $this-&gt;hr();
+        $this-&gt;out('');
+        exit;
+    }
+    
+    /**
+    * Modifies the out method for prettier formatting
+    *
+    * @param string $sString String to output.
+    * @param boolean $bNewline If true, the outputs gets an added newline.
+    */
+    function out($sString, $bNewline = true) {
+        return parent::out(&quot;  &quot;.$sString, $bNewline);
+    }
+    
+    /**
+    * Help method
+    */
+    function help(){
+        $this-&gt;hr();
+        $this-&gt;out('');
+        $this-&gt;out('Database migrations is a version control system for your database,');
+        $this-&gt;out('allowing you to migrate your database schema between versions.');
+        $this-&gt;out('');
+        $this-&gt;out('Each version is depicted by a migration file written in YAML and must');
+        $this-&gt;out('include an UP and DOWN section. The UP section is parsed and run when');
+        $this-&gt;out('migrating up and vice versa.');
+        $this-&gt;out('');
+        $this-&gt;hr();
+        $this-&gt;out('');
+        $this-&gt;out('COMMAND LINE OPTIONS');
+        $this-&gt;out('');
+        $this-&gt;out('  cake migrate');
+        $this-&gt;out('    - Migrates to the latest version (the last migration file)');
+        $this-&gt;out('');
+        $this-&gt;out('  cake migrate -v [version number]');
+        $this-&gt;out('    - Migrates to the version specified [version number]');
+        $this-&gt;out('');
+        $this-&gt;out('  cake migrate reset');
+        $this-&gt;out('    - Resets the current version to 0 and drops all tables.');
+        $this-&gt;out('');
+        $this-&gt;out('  cake migrate all');
+        $this-&gt;out('    - Migrates down to 0 and back up to the latest version');
+        $this-&gt;out('');
+        $this-&gt;out('  cake migrate down');
+        $this-&gt;out('    - Migrates down to the previous current version');
+        $this-&gt;out('');
+        $this-&gt;out('  cake migrate up');
+        $this-&gt;out('    - Migrates up from the current to the next version');
+        $this-&gt;out('');
+        $this-&gt;out('  cake migrate generate');
+        $this-&gt;out('    - Write an YAML file out of your current DB schema');
+        $this-&gt;out('');
+        $this-&gt;out('  cake migrate help');
+        $this-&gt;out('    - Displays this Help');
+        $this-&gt;out('');
+        $this-&gt;out(&quot;    append '-c [connection]' to the command if you want to specify the&quot;);
+        $this-&gt;out('    connection to use from database.php. By default it uses &quot;default&quot;');
+        $this-&gt;out('');
+        $this-&gt;out('');
+        $this-&gt;out('For more information and for the latest release of this and others,');
+        $this-&gt;out('go to http://ovalpixels.com');
+        $this-&gt;out('');
+        $this-&gt;hr();
+        $this-&gt;out('');
+    }
+
+    /**
+    * Aliases for the help method
+    */
+    function h() { $this-&gt;help(); }
+
+    /**
+    * Private method used to alter the destination version and run the migrating method ( _run )
+    *
+    * @access protected
+    * @param integer #iNewVersion The destination version
+    */
+    function _migrate_to_version( $iNew_version ){
+            if( !isset( $this-&gt;iTo_version ) || $iNew_version != $this-&gt;iTo_version ){
+                $this-&gt;iTo_version = $iNew_version;
+                $this-&gt;_run();
+            }
+    }
+
+    /**
+    * Protected method which does all the dirty work. Compares the destination and current version of the schema and runs the respective UPs or DOWNs
+    */
+    function _run(){
+        $this-&gt;hr();
+
+        if( $this-&gt;iCurrent_version == $this-&gt;iTo_version ){
+            $this-&gt;out('');
+            $this-&gt;out('  ** Migration version is the same as the current version **');
+            $this-&gt;out('');
+            $this-&gt;hr();
+            $this-&gt;out('');
+            exit;    
+        }
+        if ($this-&gt;iMigration_count === 0){
+            $this-&gt;out('');
+            $this-&gt;out('  ** No migrations found **');
+            $this-&gt;out('');
+            $this-&gt;hr();
+            $this-&gt;out('');
+            exit;
+        }
+        $iNew_version = $this-&gt;iTo_version;
+
+        if (!is_numeric($iNew_version)){
+            $this-&gt;out('');
+            $this-&gt;out('  ** Migration version number ('.$iNew_version.') is invalid. **');
+            $this-&gt;out('');
+            $this-&gt;hr();
+            $this-&gt;out('');
+            exit;
+        }
+        if ($iNew_version &gt; $this-&gt;iMigration_count){
+            $this-&gt;out('');
+            $this-&gt;out('  ** Version number entered ('.$iNew_version.') does not exist. **');
+            $this-&gt;out('');
+            $this-&gt;hr();
+            $this-&gt;out('');
+            exit;
+        }
+
+        $sDirection = ($iNew_version &lt; $this-&gt;iCurrent_version) ? 'down' : 'up';
+        if ($sDirection == 'down') usort($this-&gt;aMigrations, array($this, '_downMigrations'));
+        elseif ($sDirection == 'up') usort($this-&gt;aMigrations, array($this, '_upMigrations'));
+
+        $this-&gt;out('');
+        $this-&gt;out(&quot;Migrating database $sDirection from version {$this-&gt;iCurrent_version} to $iNew_version ...&quot;);
+        $this-&gt;out('');
+
+        foreach($this-&gt;aMigrations as $sMigration_name){
+            preg_match(&quot;/^([0-9]+)\_(.+)(\.yml)$/&quot;, $sMigration_name, $aMatch);
+            $iNum = $this-&gt;_versionIt($aMatch[1]);
+            $sName = Inflector::humanize($aMatch[2]);
+
+            if ($sDirection == 'up'){
+                if ($iNum &lt;= $this-&gt;iCurrent_version) continue;
+                if ($iNum &gt; $iNew_version) break;
+            }
+            elseif( $sDirection == 'down' ){
+                if ($iNum &gt; $this-&gt;iCurrent_version) continue;
+                if ($iNum == $iNew_version) break;
+            }
+
+            $this-&gt;out(&quot;  [$iNum] $sName ...&quot;);
+
+            $rRes = $this-&gt;_loadMigration(MIGRATIONS_PATH .DS. $sMigration_name, $sDirection);
+            if ($rRes === true){
+                $this-&gt;out('');
+                if ($sDirection == 'up'){
+                    $this-&gt;_updateVersion( 'version+1' );
+                }
+                else{
+                    $this-&gt;_updateVersion( 'version-1' );
+                }
+            }
+            elseif( is_numeric( $rRes ) &amp;&amp; $rRes &lt; 1 ){
+                $this-&gt;out('Generic error: '.$rRes );
+                $this-&gt;hr();
+                exit;
+            }
+            else{
+                $this-&gt;out(&quot;  ERROR: &quot;);
+                foreach( $rRes as $aErr ){
+                    $this-&gt;out('Query: '.$aErr['sql']);
+                    $this-&gt;out('');
+                    $this-&gt;out('Error: '.$aErr['error']);
+                }
+                $this-&gt;hr();
+                exit;
+            }
+        }
+    }
+    
+    /**
+    * Loads the file with the YAML migration schema and runs the generates the SQL script for the specified direction
+    *
+    * @access protected
+    * @param string $sFile Path to the file
+    * @param string $sFile Path to the file
+    * @return mixed False on failure and a SQL command on success
+    */
+    function _loadMigration( $sFile, $sDirection ){
+        if( !$bLoad = $this-&gt;oMigrations-&gt;load($sFile) ){
+            return $bLoad;
+        }
+        else
+            return $this-&gt;oMigrations-&gt;{$sDirection}();
+    }
+
+    /**
+    * An internal sort method - used with usort(). Sorts from top to bottom
+    *
+    * @access protected
+    * @param string $sA Name of a migration ( with the number in front )
+    * @param string $sB Name of a migration ( with the number in front )
+    * @return int &lt; = &gt;
+    */
+    function _upMigrations($sA, $sB){
+        list($aStr) = explode('_', $sA);
+        list($bStr) = explode('_', $sB);
+        $aNum = (int)$aStr;
+        $bNum = (int)$bStr;
+        if ($aNum == $bNum){
+            return 0;
+        }
+        return ($aNum &gt; $bNum) ? 1 : -1;
+    }
+
+    /**
+    * An internal sort method - used with usort(). Sorts from bottom to top
+    *
+    * @access protected
+    * @param string $sA Name of a migration ( with the number in front )
+    * @param string $sB Name of a migration ( with the number in front )
+    * @return int &lt; = &gt;
+    */
+    function _downMigrations($sA, $sB){
+        list($aStr) = explode('_', $sA);
+        list($bStr) = explode('_', $sB);
+        $aNum = (int)$aStr;
+        $bNum = (int)$bStr;
+        if ($aNum == $bNum) {
+            return 0;
+        }
+        return ($aNum &gt; $bNum) ? -1 : 1;
+    }
+
+    /**
+    * Gets the current schema version from the DB. If schema_info doesn't exist - it tries to create it.
+    *
+    * @access protected
+    * @return int Current schema version
+    */
+    function _getMigrationVersion(){
+        //load tables and see if schema_info already exists. If not, create it
+        $sTables = $this-&gt;oMigrations-&gt;oDb-&gt;listSources();
+        if( !in_array( $this-&gt;oMigrations-&gt;oDb-&gt;config['prefix'].'schema_info', $sTables ) ){
+            $this-&gt;oMigrations-&gt;oDb-&gt;query( 
+                $this-&gt;oMigrations-&gt;create_table(
+                    'schema_info', 
+                    array(  0 =&gt; 'no_id',
+                            1 =&gt; 'no_dates', 
+                            'version' =&gt; 
+                                array( 'type' =&gt; 'int', 'length' =&gt; 3, 'default' =&gt; '0' ) ) 
+                 )
+            );
+            //feed it with some data
+            App::import('model');
+            $oTemp_model = new Model( false, 'schema_info' );
+            $oTemp_model-&gt;saveField( 'version', '0' );
+            $this-&gt;iCurrent_version = 0;
+
+        }
+        else{
+            App::import('model');
+            $oTemp_model = new Model( false, 'schema_info' );
+            $this-&gt;iCurrent_version = $oTemp_model-&gt;field( 'version' );
+        }
+    }
+
+    /**
+    * Update the current shchema version in the database
+    *
+    * @access protected
+    * @param mixed $sVersion The new schema version. Can be either an integer ( 1, 2, 3 ) or an expression ( version + 1 )
+    * @return void
+    */
+    function _updateVersion($sVersion){
+        App::import('model');
+        $oTemp_model = new Model( false, 'schema_info' );
+        $oTemp_model-&gt;updateAll( array( 'version' =&gt; $sVersion ) );
+        $this-&gt;_getMigrationVersion();
+    }
+    
+    /**
+    * Loads the migration yaml files into an array ( self::aMigrations )
+    *
+    * @access protected
+    * @return void
+    */
+    function _getMigrations(){
+        $oFolder = new Folder(MIGRATIONS_PATH, true, 0777);
+        $this-&gt;aMigrations = $oFolder-&gt;find(&quot;[0-9]+_.+\.yml&quot;);
+        usort($this-&gt;aMigrations, array($this, '_upMigrations'));
+        $this-&gt;iMigration_count = count($this-&gt;aMigrations);
+    }
+
+    /**
+    * Converts migration number to a minimum three digit number.
+    *
+    * @param $iNum The number to convert
+    * @return integer The converted three digit number
+    */
+    function _versionIt($iNum){
+        switch (strlen($iNum)){
+            case 1:
+                return '00'.$iNum;
+            case 2:
+                return '0'.$iNum;
+            default:
+                return $iNum;
+        }
+    }
+    
+    /**
+    * Welcome method
+    */
+    function _welcome(){
+        $this-&gt;out('');
+        $this-&gt;out(' __  __  _  _  __     ___     __   __   __  ___    __  _  _  __ ');
+        $this-&gt;out('|   |__| |_/  |__    | | | | | _  |__| |__|  |  | |  | |\ | |__ ');
+        $this-&gt;out('|__ |  | | \_ |__    | | | | |__| | \_ |  |  |  | |__| | \|  __|');
+        $this-&gt;out('');
+    }
 }
\ No newline at end of file</diff>
      <filename>shells/migrate.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cda9ea229e60be72d88c91a3a2c3a0ff68c993bc</id>
    </parent>
  </parents>
  <author>
    <name>Georgi Momchilov</name>
    <email>georgious@georgious-laptop.lan</email>
  </author>
  <url>http://github.com/georgious/cakephp-yaml-migrations-and-fixtures/commit/758c22357482e68cd9209389735792d569242b39</url>
  <id>758c22357482e68cd9209389735792d569242b39</id>
  <committed-date>2008-06-13T04:45:53-07:00</committed-date>
  <authored-date>2008-06-13T04:45:53-07:00</authored-date>
  <message>migrations prefix fix</message>
  <tree>edf31287982bd457f659d8b99eddd3aada85ce92</tree>
  <committer>
    <name>Georgi Momchilov</name>
    <email>georgious@georgious-laptop.lan</email>
  </committer>
</commit>
