Reputation: 1
I'm trying to integrate doctrine/migrations into the TP5 framework for unit testing purposes, so I need to use the API provided by doctrine-migrations to run migrations instead of the CLI. However, I encountered this error when using the SQLite engine: The metadata storage is not initialized, please run the sync-metadata-storage command to fix this issue.
There is my code
$connectionLoader = new ConfigurationFile('./migrations-db.php');
$configurationLoader = new ConfigurationFileWithFallback('./migrations.php');
$dependencyFactory = DependencyFactory::fromConnection($configurationLoader, $connectionLoader);
$version = $dependencyFactory->getVersionAliasResolver()->resolveVersionAlias('latest');
$planCalculator = $dependencyFactory->getMigrationPlanCalculator();
$plan = $planCalculator->getPlanUntilVersion($version);
$migrator = $dependencyFactory->getMigrator();
$migratorConfigurationFactory = $dependencyFactory->getConsoleInputMigratorConfigurationFactory();
$migratorConfiguration = $migratorConfigurationFactory->getMigratorConfiguration(new ArrayInput([]));
$sql = $migrator->migrate($plan, $migratorConfiguration);
There is my migrations-db.php
<?php
// return [
// 'driver' => 'pdo_mysql',
// 'host' => '127.0.0.1',
// 'port' => 13306,
// 'password' => 'zhihui',
// 'dbname' => 'migration',
// 'user' => 'root',
// ];
return [
'driver' => 'pdo_sqlite',
'dbname' => ':memory:',
];
As you can see, everything works fine when the driver is 'mysql_pdo'.
However, strangely enough, no matter which driver I choose, running doctrine-migrations:migrate in the CLI works without any issues."
Upvotes: 0
Views: 49
Reputation: 1
I've already resolved this issue, and I found a way to call sync-metadata-storage within the Doctrine\Migrations\Tools\Console\Command\SyncMetadataCommand::execute
method.
So I just need add this line
$dependencyFactory->getMetadataStorage()->ensureInitialized();
Upvotes: 0