Migrations for eZ Publish 5, based on Doctrine Migrations, very similar to Symfony's DoctrineMigrationsBundle.
Follow these steps to install the bundle in your eZ Publish 5 project.
Add the following to your composer.json file:
{
"require": {
"doctrine/migrations": "1.0.0-alpha3",
"kreait/ezpublish-migrations-bundle": "~1.0"
}
}
Update the vendor libraries:
$ php composer.phar update
If everything worked, the EzPublishMigrationsBundle can now be found at vendor/kreait/ezpublish-migrations-bundle.
Finally, be sure to enable the bundle in EzPublishKernel.php by including the following:
// ezpublish/EzPublishKernel.php
public function registerBundles()
{
$bundles = array(
//...
new Kreait\EzPublish\MigrationsBundle\KreaitEzPublishMigrationsBundle(),
);
}
You can configure the path, namespace, table_name and name in your config.yml. The examples below are the default values.
// ezpublish/config/config.yml
ezpublish_migrations:
dir_name: %kernel.root_dir%/EzPublishMigrations
namespace: Application\Migrations
table_name: ezmigration_versions
name: Application Migrations
ez_user: admin
All of the migrations functionality is contained in the following commands:
ezpublish:migrations
:execute Execute a single migration version up or down manually.
:generate Generate a blank migration class.
:migrate Execute a migration to a specified version or the latest available version.
:status View the status of a set of migrations.
:version Manually add and delete migration versions from the version table.
The usage is identical to Symfony's DoctrineMigrationBundle, except for the missing :diff
command.
Please have a look at the
official documentation
for further information.
You can change the current eZ Publish user inside a migration by issuing the following command:
$this->changeMigrationUser('another_username');
and restore the default Migration user by using:
$this->restoreDefaultMigrationUser();
See src/Resources/doc/examples for some usage examples.
When you create a migration using only eZ Publish's API methods, no actual SQL statements are executed. This results in the following message:
Migration was executed but did not result in any SQL statements.
You can avoid this message by adding a dummy SQL statement at the end of your up()
and down()
method:
public function up(Schema $schema)
{
// ...
$this->addSql("SELECT 'Description of what we did here'");
}
- Doctrine Project for the Doctrine Database Migrations providing the underlying migration functionality
- Symfony for the DoctrineMigrationsBundle being the blueprint for this bundle
- Magic Internet GmbH, especially @m-keil for the initial methodical blueprint