Roave / psr-container-doctrine

Doctrine Factories for PSR-11 Containers
BSD 2-Clause "Simplified" License
95 stars 32 forks source link

Missing configuration file when using the CLI #69

Closed drakulitka closed 2 years ago

drakulitka commented 2 years ago

Please help me how to fix the error?

command php vendor/bin/doctrine-migrations migrations:diff causes an error:

    Fatal error: Uncaught Doctrine\Migrations\Configuration\Migration\Exception\MissingConfigurationFile: It was not possible to locate any configuration file. in /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/Configuration/Migration/Exception/MissingConfigurationFile.php:14
    Stack trace:
    #0 /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/Configuration/Migration/ConfigurationFileWithFallback.php(52): Doctrine\Migrations\Configuration\Migration\Exception\MissingConfigurationFile::new()
    #1 /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/DependencyFactory.php(161): Doctrine\Migrations\Configuration\Migration\ConfigurationFileWithFallback->getConfiguration()
    #2 /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/DependencyFactory.php(187): Doctrine\Migrations\DependencyFactory->getConfiguration()
    #3 /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/DependencyFactory.php(279): Doctrine\Migrations\DependencyFactory->getEntityManager()
    #4 /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/Depen in /app/vendor/doctrine/migrations/lib/Doctrine/Migrations/Configuration/Migration/Exception/MissingConfigurationFile.php on line 14

file cli-config.php:

    <?php
    $container = require 'config/container.php';
    /** @var \Doctrine\ORM\EntityManager $entityManager */
    $entityManager = $container->get(\Doctrine\ORM\EntityManager::class);
    return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet(
        $container->get(\Doctrine\ORM\EntityManager::class)
    );

file config/autoload/doctrine.local.php:

    <?php
    declare(strict_types=1);
    use Doctrine\Migrations\Tools\Console\Command;
    return [
        'doctrine' => [
            'connection' => [
                'orm_default' => [
                    'params' => [ ],
                ],
            ],
            'migrations' => [
                'orm_default' => [
                    'table_storage' => [
                        'table_name' => 'migrations',
                        'version_column_name' => 'version',
                        'version_column_length' => 255,
                        'executed_at_column_name' => 'executed_at',
                        'execution_time_column_name' => 'execution_time',
                    ],
                    'migrations_paths' => ['DB\Migrations' => __DIR__ . '/../../data/migrations'],
                    'all_or_nothing' => true,
                    'check_database_platform' => true,
                ],
            ],
        ],
        'dependencies' => [
            'factories' => [
                Command\DiffCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
                Command\DumpSchemaCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
                Command\ExecuteCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
                Command\GenerateCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
                Command\LatestCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
                Command\MigrateCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
                Command\RollupCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
                Command\StatusCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
                Command\UpToDateCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
                Command\VersionCommand::class => Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,
                Doctrine\Migrations\DependencyFactory::class => Roave\PsrContainerDoctrine\Migrations\DependencyFactoryFactory::class,
                Doctrine\Migrations\Configuration\Migration\ConfigurationLoader::class => Roave\PsrContainerDoctrine\Migrations\ConfigurationLoaderFactory::class,
            ],
        ],
    ];
Ocramius commented 2 years ago

I think you need one of these files in your $CWD: https://github.com/doctrine/migrations/blob/8b9391f455d08fb0a9734bd0061457380e75858b/lib/Doctrine/Migrations/Configuration/Migration/ConfigurationFileWithFallback.php#L38-L44

drakulitka commented 2 years ago

I think you need one of these files in your $CWD:

What kind of settings should this file contain? Are there any examples? Shouldn't the settings be picked up from the array? 'migrations' => [ 'orm_default' => [ ] ] in the file config/autoload/doctrine.local.php

Ocramius commented 2 years ago

See https://github.com/doctrine/migrations/blob/3.4.1/docs/en/reference/configuration.rst

drakulitka commented 2 years ago

See https://github.com/doctrine/migrations/blob/3.4.1/docs/en/reference/configuration.rst

Thank you very much! Everything works perfectly!