3

I have been using Doctrine and Migrations in my ZF2 project for a few weeks without issue. I have been executing migrations by specifying my own configuration file:

vendor/bin/doctrine-module migrations:diff --configuration=/path/to/migrations-config.xml

I recently brought in Codeception into my project via composer and when I recently went to execute a new migration (with the same above command), I received the following error:

[InvalidArgumentException]
Migrations directory data/DoctrineORMModule/Migrations does not exist

This is not the directory I have specified in my configuration file. At first I thought Doctrine Migrations was completely ignoring my --configuration argument. When I traced it through, I saw that Doctrine Migrations wasn't using my --configuration argument because it had already loaded a config file.

Would anyone know where this config file may be pulling in from? I can work around the issue for the time being by commenting out the conditional in AbstractCommand getMigrationConfiguration(), but long term I'd rather not have to rely on this. I'll also try and remove codeception and see if that has any impact. Any help is appreciated.

Jon
  • 1,234
  • 2
  • 12
  • 30

2 Answers2

7

As it turns out, I was able to move Doctrine migrations configuration into my ZF2 module config. In my module.config.php, I have the following specified (Api is the module name):

'doctrine' => array(
        'driver' => array(
            'application_entities' => array(
                'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../src/Api/Entity')
            ),
            'orm_default' => array(
                'drivers' => array(
                    'Api\Entity' => 'application_entities'
                )
            )
        ),
        'migrations_configuration' => array(
            'orm_default' => array(
                'directory' => 'data/migrations',
                'namespace' => 'My\Namespace\Migrations',
                'table' => 'migrations',
            ),  
        ),
    ),

This allows me to run Doctrine migrations commands without having to specify a configuration file, for example:

vendor/bin/doctrine-module migrations:diff
Jon
  • 1,234
  • 2
  • 12
  • 30
1

I see an alternative in using a stand-alone doctrine-migration.phar command:

php doctrine-migrations.phar migrations:migrate --configuration=config.xml --db-configuration=db-config.xml

To make this work, you need to download doctrine-migrations.phar from here: https://github.com/doctrine/migrations

OlegKrivtsov
  • 752
  • 4
  • 9
  • Thanks for the suggestion. I ruled out Codeception, so there's something else going on. If I can't track down the issue in my project, I'll give your suggestion a go. – Jon Feb 03 '14 at 12:13