This repository has been archived by the owner on Dec 8, 2017. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# ZenstruckMigrationsBundle | ||
|
||
Wrapper for DoctrineMigrationsBundle that enables container aware migrations. | ||
|
||
## Installation | ||
|
||
1. Add this bundle to your project | ||
* Using `deps` file | ||
|
||
```ini | ||
[ZenstruckMigrationsBundle] | ||
git=git://github.com/kbond/ZenstruckMigrationsBundle.git | ||
target=bundles/Zenstruck/Bundle/MigrationsBundle | ||
``` | ||
* Using submodules | ||
|
||
``` | ||
git submodule add git://github.com/kbond/ZenstruckMigrationsBundle.git vendor/bundles/Zenstruck/Bundle/MigrationsBundle | ||
``` | ||
|
||
2. Register the namespaces | ||
|
||
```php | ||
<?php | ||
// app/autoload.php | ||
$loader->registerNamespaces(array( | ||
// ... | ||
'Zenstruck' => __DIR__.'/../vendor/bundles', | ||
// ... | ||
)); | ||
``` | ||
|
||
3. Register the bundle | ||
|
||
```php | ||
<?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`) | ||
* _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 | ||
<?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 | ||
} | ||
|
||
/** | ||
* OPTIONAL | ||
*/ | ||
public function getDataDescription() | ||
{ | ||
return parent::getDataDescription(); | ||
} | ||
} | ||
``` |