1

Good Day, my friends.

I want to use the doctrine ORM with the Migrations.

The issue is next: I want to place the migration configuration file in the specific folder. For example: 'config/doctrine-migrations.php'.

Everything working fine when I follow the official documentation and place the migrations.php file in the root folder, but when I try to place it in the specific folder system is not working.

My cli-config.php content is:

<?php

require_once "app/bootstrap.php";

return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($container->get(\Doctrine\ORM\EntityManager::class));

Well, I can change this file in a next way:

<?php

require_once "app/bootstrap.php";

return \Doctrine\Migrations\DependencyFactory::fromEntityManager(
    new \Doctrine\Migrations\Configuration\Migration\PhpFile(BP . '/config/doctrine-migrations.php'),
    new \Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager($container->get(\Doctrine\ORM\EntityManager::class))
);

After this, Doctrine Migration working fine, but Doctrine ORM stop working with the next error:

Argument #1 ($helperSet) must be of type Symfony\Component\Console\Helper\HelperSet, Doctrine\Migrations\DependencyFactory given

If someone knows how to solve my issue and use a specific config file please clarify a possible solution.

Best Regards, Mavis.

Mavis
  • 75
  • 8

2 Answers2

1

I may be a bit late, but i ran into the same problem as you. You can use the same cli-config for migrations and orm. For that, you need add the orm commands manually to the cli-config.php.

My cli config looks like this:

$em = getEntityManager();

$config = new PhpFile('migrations.php');
$dependencyFactory = DependencyFactory::fromEntityManager($config, new ExistingEntityManager($em));

$migrationCommands = [
    new Command\DumpSchemaCommand($dependencyFactory),
    new Command\ExecuteCommand($dependencyFactory),
    new Command\GenerateCommand($dependencyFactory),
    new Command\LatestCommand($dependencyFactory),
    new Command\ListCommand($dependencyFactory),
    new Command\MigrateCommand($dependencyFactory),
    new Command\RollupCommand($dependencyFactory),
    new Command\StatusCommand($dependencyFactory),
    new Command\SyncMetadataCommand($dependencyFactory),
    new Command\VersionCommand($dependencyFactory),
];

$customCommands = [];

$commands = array_merge($migrationCommands, $customCommands);

ConsoleRunner::run(new SingleManagerProvider($em), $commands);

All my import statements, are not included in this example, but you can get them from the docrtine documentation

firesnake
  • 11
  • 1
  • 2
0

Looks like I found an answer.

I can add custom integration in my application by this guide: https://www.doctrine-project.org/projects/doctrine-migrations/en/3.0/reference/custom-integration.html

In a custom file, I can configure whatever I want.

Hope that this solution will help somebody else.

Mavis
  • 75
  • 8