zenstruck / migrations-bundle
Wrapper for DoctrineMigrationsBundle that enables container aware migrations
Fund package maintenance!
kbond
Installs: 1 121
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 4
Open Issues: 1
Type:symfony-bundle
Requires
This package is not auto-updated.
Last update: 2022-02-01 12:20:27 UTC
README
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
-
Add to
composer.json
(see http://getcomposer.org/)"require" : { "zenstruck/migrations-bundle": "*", }
-
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 extendDoctrine\DBAL\Migrations\AbstractMigration
will still run normally) - Implement the
dataUp()
method and add your custom migration logic. (note: Theup()
method will be run beforedataUp
) - Implement the
dataDown()
method and add your custom migration logic. (note: Thedown()
method will be run beforedataDown
) - 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 notdoctrine: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(); } }