diff --git a/composer.json b/composer.json index 2ce2f63a36..f848bfaa05 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "require-dev": { "ext-pdo_sqlite": "*", "doctrine/coding-standard": "^9", - "doctrine/orm": "^2.12", + "doctrine/orm": "^2.13", "doctrine/persistence": "^2 || ^3", "doctrine/sql-formatter": "^1.0", "phpstan/phpstan": "^1.5", diff --git a/docs/en/reference/configuration.rst b/docs/en/reference/configuration.rst index 06af262832..d451c1ac35 100644 --- a/docs/en/reference/configuration.rst +++ b/docs/en/reference/configuration.rst @@ -27,7 +27,7 @@ Now, in the root of your project place a file named ``migrations.php``, ``migrat 'table_storage' => [ 'table_name' => 'doctrine_migration_versions', 'version_column_name' => 'version', - 'version_column_length' => 1024, + 'version_column_length' => 191, 'executed_at_column_name' => 'executed_at', 'execution_time_column_name' => 'execution_time', ], @@ -50,7 +50,7 @@ Now, in the root of your project place a file named ``migrations.php``, ``migrat table_storage: table_name: doctrine_migration_versions version_column_name: version - version_column_length: 1024 + version_column_length: 191 executed_at_column_name: executed_at execution_time_column_name: execution_time @@ -81,7 +81,7 @@ Now, in the root of your project place a file named ``migrations.php``, ``migrat @@ -104,7 +104,7 @@ Now, in the root of your project place a file named ``migrations.php``, ``migrat "table_storage": { "table_name": "doctrine_migration_versions", "version_column_name": "version", - "version_column_length": 1024, + "version_column_length": 191, "executed_at_column_name": "executed_at", "execution_time_column_name": "execution_time" }, @@ -164,7 +164,7 @@ Here the possible options for ``table_storage``: +----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+ | version_column_name | no | version | The name of the column which stores the version name. | +----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+ -| version_column_length | no | 1024 | The length of the column which stores the version name. | +| version_column_length | no | 191 | The length of the column which stores the version name. | +----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+ | executed_at_column_name | no | executed_at | The name of the column which stores the date that a migration was executed. | +----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+ diff --git a/lib/Doctrine/Migrations/Provider/OrmSchemaProvider.php b/lib/Doctrine/Migrations/Provider/OrmSchemaProvider.php index 1f69bb8a9e..92c0faab8f 100644 --- a/lib/Doctrine/Migrations/Provider/OrmSchemaProvider.php +++ b/lib/Doctrine/Migrations/Provider/OrmSchemaProvider.php @@ -5,12 +5,10 @@ namespace Doctrine\Migrations\Provider; use Doctrine\DBAL\Schema\Schema; -use Doctrine\Migrations\Provider\Exception\NoMappingFound; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Tools\SchemaTool; -use function count; use function usort; /** @@ -29,18 +27,11 @@ public function __construct(EntityManagerInterface $em) $this->entityManager = $em; } - /** - * @throws NoMappingFound - */ public function createSchema(): Schema { /** @var array> $metadata */ $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata(); - if (count($metadata) === 0) { - throw NoMappingFound::new(); - } - usort($metadata, static function (ClassMetadata $a, ClassMetadata $b): int { return $a->getTableName() <=> $b->getTableName(); }); diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php index 13394258c5..24a48df838 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php @@ -75,7 +75,8 @@ protected function configure(): void 'all-or-nothing', null, InputOption::VALUE_OPTIONAL, - 'Wrap the entire migration in a transaction.' + 'Wrap the entire migration in a transaction.', + 'notprovided' ) ->setHelp(<<%command.name% command executes a migration to a specified version or the latest available version: diff --git a/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php b/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php index 04ee777b37..853b289132 100644 --- a/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php +++ b/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php @@ -21,12 +21,26 @@ public function getMigratorConfiguration(InputInterface $input): MigratorConfigu { $timeAllQueries = $input->hasOption('query-time') ? (bool) $input->getOption('query-time') : false; $dryRun = $input->hasOption('dry-run') ? (bool) $input->getOption('dry-run') : false; - $allOrNothing = $input->hasOption('all-or-nothing') ? $input->getOption('all-or-nothing') : null; - $allOrNothing = (bool) ($allOrNothing ?? $this->configuration->isAllOrNothing()); + $allOrNothing = $this->determineAllOrNothingValueFrom($input) ?? $this->configuration->isAllOrNothing(); return (new MigratorConfiguration()) ->setDryRun($dryRun) ->setTimeAllQueries($timeAllQueries) ->setAllOrNothing($allOrNothing); } + + private function determineAllOrNothingValueFrom(InputInterface $input): ?bool + { + $allOrNothingOption = null; + + if ($input->hasOption('all-or-nothing')) { + $allOrNothingOption = $input->getOption('all-or-nothing'); + } + + if ($allOrNothingOption === 'notprovided') { + return null; + } + + return (bool) ($allOrNothingOption ?? true); + } } diff --git a/tests/Doctrine/Migrations/Tests/Configuration/EntityManager/_files/em-loader.php b/tests/Doctrine/Migrations/Tests/Configuration/EntityManager/_files/em-loader.php index ad0d048ec9..2f20bb724b 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/EntityManager/_files/em-loader.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/EntityManager/_files/em-loader.php @@ -19,6 +19,6 @@ public function getEntityManager(?string $name = null): EntityManagerInterface $conf->setProxyNamespace('Foo'); $conf->setMetadataDriverImpl(new PHPDriver('')); - return EntityManager::create($conn, $conf); + return new EntityManager($conn, $conf); } }; diff --git a/tests/Doctrine/Migrations/Tests/Configuration/EntityManager/_files/migrations-em.php b/tests/Doctrine/Migrations/Tests/Configuration/EntityManager/_files/migrations-em.php index 3bd4912dbe..df565ec2f9 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/EntityManager/_files/migrations-em.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/EntityManager/_files/migrations-em.php @@ -14,4 +14,4 @@ $conf->setProxyNamespace('Foo'); $conf->setMetadataDriverImpl(new PHPDriver('')); -return EntityManager::create($conn, $conf); +return new EntityManager($conn, $conf); diff --git a/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php b/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php index 248f2a02d3..081646dd5e 100644 --- a/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php +++ b/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php @@ -12,7 +12,6 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\ORM\ORMSetup; -use UnexpectedValueException; /** * Tests the OrmSchemaProvider using a real entity manager. @@ -37,10 +36,14 @@ public function testCreateSchemaFetchesMetadataFromEntityManager(): void } } - public function testEntityManagerWithoutMetadataCausesError(): void + /** + * It should be OK to use migrations to manage tables not managed by + * the ORM. + * + * @doesNotPerformAssertions + */ + public function testEntityManagerWithoutMetadata(): void { - $this->expectException(UnexpectedValueException::class); - $this->config->setMetadataDriverImpl(new XmlDriver([])); $this->ormProvider->createSchema(); @@ -52,7 +55,7 @@ protected function setUp(): void $this->config->setClassMetadataFactoryName(ClassMetadataFactory::class); $this->conn = $this->getSqliteConnection(); - $this->entityManager = EntityManager::create($this->conn, $this->config); + $this->entityManager = new EntityManager($this->conn, $this->config); $this->ormProvider = new OrmSchemaProvider($this->entityManager); } } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php index 71aa4344d0..3838137ae6 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php @@ -362,7 +362,7 @@ public function testExecuteMigrateDown(): void } /** - * @psalm-param array $input + * @psalm-param array $input * * @dataProvider allOrNothing */ @@ -390,13 +390,22 @@ public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool } /** - * @psalm-return Generator, bool}> + * @psalm-return Generator, bool}> */ public function allOrNothing(): Generator { yield [false, ['--all-or-nothing' => false], false]; + yield [false, ['--all-or-nothing' => 0], false]; + yield [false, ['--all-or-nothing' => '0'], false]; + yield [false, ['--all-or-nothing' => true], true]; + yield [false, ['--all-or-nothing' => 1], true]; + yield [false, ['--all-or-nothing' => '1'], true]; + yield [false, ['--all-or-nothing' => null], true]; + yield [true, ['--all-or-nothing' => false], false]; + yield [true, ['--all-or-nothing' => 0], false]; + yield [true, ['--all-or-nothing' => '0'], false]; yield [true, [], true]; yield [false, [], false]; diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/config/cli-config.php b/tests/Doctrine/Migrations/Tests/Tools/Console/config/cli-config.php index dd99d78069..d73e28cd3c 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/config/cli-config.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/config/cli-config.php @@ -17,7 +17,7 @@ $conn = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]); -$em = EntityManager::create($conn, $conf); +$em = new EntityManager($conn, $conf); $config = new ConfigurationArray([ 'custom_template' => 'foo', diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-orm/cli-config.php b/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-orm/cli-config.php index ff8927b53f..c9c8a60834 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-orm/cli-config.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-orm/cli-config.php @@ -16,7 +16,7 @@ $conn = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]); -$em = EntityManager::create($conn, $conf); +$em = new EntityManager($conn, $conf); return new HelperSet([ 'em' => new EntityManagerHelper($em),