Skip to content

Commit

Permalink
Add new configuration options.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed Jun 5, 2018
1 parent 2df74bf commit 2f223bb
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 27 deletions.
5 changes: 5 additions & 0 deletions Command/DoctrineCommand.php
Expand Up @@ -81,6 +81,11 @@ public static function configureMigrations(ContainerInterface $container, Config
$configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
}

$configuration->setMigrationsColumnName($container->getParameter('doctrine_migrations.column_name'));
$configuration->setMigrationsColumnLength($container->getParameter('doctrine_migrations.column_length'));
$configuration->setMigrationsExecutedAtColumnName($container->getParameter('doctrine_migrations.executed_at_column_name'));
$configuration->setAllOrNothing($container->getParameter('doctrine_migrations.all_or_nothing'));

// Migrations is not register from configuration loader
if (! ($configuration instanceof AbstractFileConfiguration)) {
$migrationsDirectory = $configuration->getMigrationsDirectory();
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/Configuration.php
Expand Up @@ -36,6 +36,10 @@ public function getConfigTreeBuilder() : TreeBuilder
->scalarNode('dir_name')->defaultValue('%kernel.root_dir%/DoctrineMigrations')->cannotBeEmpty()->end()
->scalarNode('namespace')->defaultValue('Application\Migrations')->cannotBeEmpty()->end()
->scalarNode('table_name')->defaultValue('migration_versions')->cannotBeEmpty()->end()
->scalarNode('column_name')->defaultValue('version')->end()
->scalarNode('column_length')->defaultValue(255)->end()
->scalarNode('executed_at_column_name')->defaultValue('executed_at')->end()
->scalarNode('all_or_nothing')->defaultValue(false)->end()
->scalarNode('name')->defaultValue('Application Migrations')->end()
->scalarNode('custom_template')->defaultValue(null)->end()
->scalarNode('organize_migrations')->defaultValue(false)
Expand Down
86 changes: 59 additions & 27 deletions Resources/doc/index.rst
Expand Up @@ -54,12 +54,16 @@ You can configure the path, namespace, table_name, name, organize_migrations and
# app/config/config.yml
doctrine_migrations:
dir_name: "%kernel.root_dir%/DoctrineMigrations"
namespace: Application\Migrations
table_name: migration_versions
dir_name: "%kernel.root_dir%/Migrations"
namespace: "DoctrineMigrations"
table_name: "migration_versions"
column_name: "version"
column_length: 255
executed_at_column_name: "executed_at"
name: Application Migrations
organize_migrations: false # Version >= 1.2, possible values are: "BY_YEAR", "BY_YEAR_AND_MONTH", false
custom_template: ~ # Version >= 1.2, path to your custom migrations template
all_or_nothing: false
Usage
-----
Expand Down Expand Up @@ -87,18 +91,25 @@ the ``status`` command:

.. code-block:: bash
php app/console doctrine:migrations:status
$ php app/console doctrine:migrations:status
== Configuration
>> Name: Application Migrations
>> Database Driver: pdo_mysql
>> Database Host: 127.0.0.1
>> Database Name: symfony_migrations
>> Configuration Source: manually configured
>> Version Table Name: migration_versions
>> Migrations Namespace: Application\Migrations
>> Migrations Directory: /path/to/project/app/DoctrineMigrations
>> Version Column Name: version
>> Migrations Namespace: DoctrineMigrations
>> Migrations Directory: /path/to/project/app/Migrations
>> Previous Version: Already at first version
>> Current Version: 0
>> Next Version: Already at latest version
>> Latest Version: 0
>> Executed Migrations: 0
>> Executed Unavailable Migrations: 0
>> Available Migrations: 0
>> New Migrations: 0
Expand All @@ -109,25 +120,41 @@ for you.
.. code-block:: bash
$ php app/console doctrine:migrations:generate
Generated new migration class to "/path/to/project/app/DoctrineMigrations/Version20100621140655.php"
Generated new migration class to "/path/to/project/app/Migrations/Version20180605020420.php"
To run just this migration for testing purposes, you can use migrations:execute --up 20180605020420
To revert the migration you can use migrations:execute --down 20180605020420
Have a look at the newly generated migration class and you will see something
like the following::

namespace Application\Migrations;
declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

class Version20100621140655 extends AbstractMigration
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20180605020420 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs

}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs

}
}
Expand All @@ -141,27 +168,34 @@ migration to execute:
== Configuration
>> Name: Application Migrations
>> Configuration Source: manually configured
>> Version Table Name: migration_versions
>> Migrations Namespace: Application\Migrations
>> Migrations Directory: /path/to/project/app/DoctrineMigrations
>> Current Version: 0
>> Latest Version: 2010-06-21 14:06:55 (20100621140655)
>> Executed Migrations: 0
>> Available Migrations: 1
>> New Migrations: 1
>> Name: Application Migrations
>> Database Driver: pdo_mysql
>> Database Host: 127.0.0.1
>> Database Name: symfony_migrations
>> Configuration Source: manually configured
>> Version Table Name: migration_versions
>> Version Column Name: version
>> Migrations Namespace: DoctrineMigrations
>> Migrations Directory: /path/to/project/app/Migrations
>> Previous Version: Already at first version
>> Current Version: 0
>> Next Version: 2018-06-05 02:04:20 (20180605020420)
>> Latest Version: 2018-06-05 02:04:20 (20180605020420)
>> Executed Migrations: 0
>> Executed Unavailable Migrations: 0
>> Available Migrations: 1
>> New Migrations: 1
== Migration Versions
== Available Migration Versions
>> 2010-06-21 14:06:55 (20100621140655) not migrated
>> 2018-06-05 02:04:20 (20180605020420) not migrated
Now you can add some migration code to the ``up()`` and ``down()`` methods and
finally migrate when you're ready:

.. code-block:: bash
$ php app/console doctrine:migrations:migrate 20100621140655
$ php app/console doctrine:migrations:migrate 20180605020420
For more information on how to write the migrations themselves (i.e. how to
fill in the ``up()`` and ``down()`` methods), see the official Doctrine Migrations
Expand Down Expand Up @@ -196,7 +230,6 @@ You can skip single migrations by explicitely adding them to the ``migration_ver
Doctrine will then assume that this migration has already been run and will ignore it.


Generating Migrations Automatically
-----------------------------------

Expand Down Expand Up @@ -228,13 +261,12 @@ for Doctrine's ORM:
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
protected $name;
}
private $name;
.. code-block:: yaml
Expand Down Expand Up @@ -406,6 +438,6 @@ This ignores the tables on the DBAL level and they will be ignored by the diff c
Note that if you have multiple connections configured then the ``schema_filter`` configuration
will need to be placed per-connection.

.. _documentation: http://docs.doctrine-project.org/projects/doctrine-migrations/en/latest/index.html
.. _documentation: https://www.doctrine-project.org/projects/doctrine-migrations/en/current/index.html
.. _DoctrineMigrationsBundle: https://github.com/doctrine/DoctrineMigrationsBundle
.. _`Doctrine Database Migrations`: https://github.com/doctrine/migrations
24 changes: 24 additions & 0 deletions Tests/Command/DoctrineCommandTest.php
Expand Up @@ -48,10 +48,30 @@ public function testConfigureMigrations() : void
->method('setMigrationsTableName')
->with('test');

$configurationMock->expects($this->once())
->method('setMigrationsColumnName')
->with('version');

$configurationMock->expects($this->once())
->method('setMigrationsColumnLength')
->with(255);

$configurationMock->expects($this->once())
->method('setMigrationsColumnLength')
->with(255);

$configurationMock->expects($this->once())
->method('setMigrationsExecutedAtColumnName')
->with('executed_at');

$configurationMock->expects($this->once())
->method('setMigrationsAreOrganizedByYear')
->with(true);

$configurationMock->expects($this->once())
->method('setAllOrNothing')
->with(false);

DoctrineCommand::configureMigrations($this->getContainer(), $configurationMock);
}

Expand All @@ -62,8 +82,12 @@ private function getContainer() : ContainerBuilder
'doctrine_migrations.namespace' => 'test',
'doctrine_migrations.name' => 'test',
'doctrine_migrations.table_name' => 'test',
'doctrine_migrations.column_name' => 'version',
'doctrine_migrations.column_length' => 255,
'doctrine_migrations.executed_at_column_name' => 'executed_at',
'doctrine_migrations.organize_migrations' => Configuration::VERSIONS_ORGANIZATION_BY_YEAR,
'doctrine_migrations.custom_template' => null,
'doctrine_migrations.all_or_nothing' => false,
]));
}
}

0 comments on commit 2f223bb

Please sign in to comment.