The Doctrine Migration tools allow you to migrate databases and it issues alter table statements 
directly to your databases when you need to deploy database changes.

++ Writing Migration Classes

Migration classes consist of a simple class that extends from Doctrine_Migration. You can define 
a public up() and down() method that is meant for doing and undoing changes to a database for that 
migration step. The class name is completely arbitrary, but the name of the file which contains the 
class must have a prefix containing the number it represents in the migration process. 
Example: XXX_representative_name.class.php

<code type="php">
// 001_add_table.class.php
class AddTable extends Doctrine_Migration
{
    public function up()
    {
        $this->createTable('migration_test', array('field1' => array('type' => 'string')));
    }
    
    public function down()
    {
        $this->dropTable('migration_test');
    }
}

// 002_add_column.class.php
class AddColumn extends Doctrine_Migration
{
    public function up()
    {
        $this->addColumn('migration_test', 'field1', 'string');
    }
    
    public function down()
    {
        $this->renameColumn('migration_test', 'field1', 'field2');
    }
}

// 003_change_column.class.php
class ChangeColumn extends Doctrine_Migration
{
    public function up()
    {
        $this->changeColumn('migration_test', 'field1', 'integer');
    }
    
    public function down()
    {
        $this->changeColumn('migration_test', 'field1', 'string');
    }  
}
</code>

+++ Methods

Here is a list of the available methods you can use to alter your database in your migration classes

<code type="php">
public function createTable($tableName, array $fields = array(), array $options = array())
public function dropTable($tableName)
public function renameTable($oldTableName, $newTableName)
public function createConstraint($tableName, $constraintName, array $definition)
public function dropConstraint($tableName, $constraintName, $primary = false)
public function createForeignKey($tableName, array $definition)
public function dropForeignKey($tableName, $fkName)
public function addColumn($tableName, $columnName, $type, array $options = array())
public function renameColumn($tableName, $oldColumnName, $newColumnName)
public function changeColumn($tableName, $columnName, $type, array $options = array())
public function removeColumn($tableName, $columnName)
public function addIndex($tableName, $indexName, array $options = array())
public function removeIndex($tableName, $indexName)
</code>

+++ Altering Data

Sometimes you may need to alter the data in the database with your models. Since you may create a table 
or make a change, you have to do the data altering after the up() or down() method is processed. We have 
hooks in place for this named preUp(), postUp(), preDown(), and postDown(). Define these methods and 
they will be triggered after the migration version is executed.

<code type="php">
// XXX_add_user.class.php
class AddUser extends Doctrine_Migration
{
    public function up()
    {
        $this->createTable('migration_test', array('field1' => array('type' => 'string')));
    }
    
    public function postUp()
    {
      $migrationTest = new MigrationTest();
      $migrationTest->field1 = 'test';
      $migrationTest->save();
    }

    public function down()
    {
        $this->dropTable('migration_test');
    }
    
    public function postDown()
    {
        $migrationTest = Doctrine::getTable('MigrationTest')->findOneByField1('test');
        $migrationTest->delete();
    }
}
</code>

++ Performing Migrations

<code type="php">
$migration = new Doctrine_Migration('/path/to/migration_classes');

// Assume current version is 0
$migration->migrate(3); // takes you from 0 to 3
$migration->migrate(0); // takes you from 3 to 0

echo $migration->getCurrentVersion(); // 0
</code>


This functionality is can also be accessed from the Doctrine command line interface.