ZenstruckMigrationsBundle

[DEPRECATED] Wrapper for DoctrineMigrationsBundle that enables container aware migrations

NOTE: DoctrineMigrationsBundle now supports ContainerAware migrations

Wrapper for DoctrineMigrationsBundle that enables container aware migrations.

NOTE: For use with Symfony 2.0 use the 1.x branch

Installation

  1. Add to composer.json (see http://getcomposer.org/)

    "require" :  {
        "zenstruck/migrations-bundle": "*",
    }
  2. Register the bundle

    <?php
    // app/AppKernel.php
    
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Zenstruck\Bundle\MigrationsBundle\ZenstruckMigrationsBundle(),
        );
        // ...
    )

Usage

  • To make use of container aware data migrations your migrations must extend Zenstruck\Bundle\MigrationsBundle\Migrations\AbstractMigration. (note: Migrations that extend Doctrine\DBAL\Migrations\AbstractMigration will still run normally)
  • Implement the dataUp() method and add your custom migration logic. (note: The up() method will be run before dataUp)
  • Implement the dataDown() method and add your custom migration logic. (note: The down() method will be run before dataDown)
  • Optionally implement the getDataDescription method and return a description of the migration.
  • Migrate using the zenstruck:migrations:migrate command. (note: make sure you run migrations with this command and not doctrine:migrations:migrate

Migration Template

<?php

namespace Application\Migrations;

use Zenstruck\Bundle\MigrationsBundle\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Auto-generated Migration: Please modify to your need!
 */
class Version20120419113825 extends AbstractMigration
{
    public function up(Schema $schema)
    {
        // this up() migration is autogenerated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");

    }

    public function down(Schema $schema)
    {
        // this down() migration is autogenerated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");

    }
    
    public function dataUp(ContainerInterface $container)
    {
        // container aware logic
    }
    
    public function dataDown(ContainerInterface $container)
    {
        // container aware logic
    }

    /**
     * OPTIONAL
     */
    public function getDataDescription()
    {
        return parent::getDataDescription();
    }
}

Copyright (c) Kevin Bond

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.