Skip to content

Commit 53303eb

Browse files
authored
Merge pull request #1299 from doctrine/3.5.x-merge-up-into-3.6.x_HpL0fw1G
2 parents 7fa9d14 + 01f89a1 commit 53303eb

File tree

11 files changed

+47
-29
lines changed

11 files changed

+47
-29
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"require-dev": {
3838
"ext-pdo_sqlite": "*",
3939
"doctrine/coding-standard": "^9",
40-
"doctrine/orm": "^2.12",
40+
"doctrine/orm": "^2.13",
4141
"doctrine/persistence": "^2 || ^3",
4242
"doctrine/sql-formatter": "^1.0",
4343
"phpstan/phpstan": "^1.5",

docs/en/reference/configuration.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Now, in the root of your project place a file named ``migrations.php``, ``migrat
2727
'table_storage' => [
2828
'table_name' => 'doctrine_migration_versions',
2929
'version_column_name' => 'version',
30-
'version_column_length' => 1024,
30+
'version_column_length' => 191,
3131
'executed_at_column_name' => 'executed_at',
3232
'execution_time_column_name' => 'execution_time',
3333
],
@@ -50,7 +50,7 @@ Now, in the root of your project place a file named ``migrations.php``, ``migrat
5050
table_storage:
5151
table_name: doctrine_migration_versions
5252
version_column_name: version
53-
version_column_length: 1024
53+
version_column_length: 191
5454
executed_at_column_name: executed_at
5555
execution_time_column_name: execution_time
5656
@@ -81,7 +81,7 @@ Now, in the root of your project place a file named ``migrations.php``, ``migrat
8181
<table-storage
8282
table-name="doctrine_migration_versions"
8383
version-column-name="version"
84-
version-column-length="1024"
84+
version-column-length="191"
8585
executed-at-column-name="executed_at"
8686
execution-time-column-name="execution_time"
8787
/>
@@ -104,7 +104,7 @@ Now, in the root of your project place a file named ``migrations.php``, ``migrat
104104
"table_storage": {
105105
"table_name": "doctrine_migration_versions",
106106
"version_column_name": "version",
107-
"version_column_length": 1024,
107+
"version_column_length": 191,
108108
"executed_at_column_name": "executed_at",
109109
"execution_time_column_name": "execution_time"
110110
},
@@ -164,7 +164,7 @@ Here the possible options for ``table_storage``:
164164
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
165165
| version_column_name | no | version | The name of the column which stores the version name. |
166166
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
167-
| version_column_length | no | 1024 | The length of the column which stores the version name. |
167+
| version_column_length | no | 191 | The length of the column which stores the version name. |
168168
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
169169
| executed_at_column_name | no | executed_at | The name of the column which stores the date that a migration was executed. |
170170
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+

lib/Doctrine/Migrations/Provider/OrmSchemaProvider.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
namespace Doctrine\Migrations\Provider;
66

77
use Doctrine\DBAL\Schema\Schema;
8-
use Doctrine\Migrations\Provider\Exception\NoMappingFound;
98
use Doctrine\ORM\EntityManagerInterface;
109
use Doctrine\ORM\Mapping\ClassMetadata;
1110
use Doctrine\ORM\Tools\SchemaTool;
1211

13-
use function count;
1412
use function usort;
1513

1614
/**
@@ -29,18 +27,11 @@ public function __construct(EntityManagerInterface $em)
2927
$this->entityManager = $em;
3028
}
3129

32-
/**
33-
* @throws NoMappingFound
34-
*/
3530
public function createSchema(): Schema
3631
{
3732
/** @var array<int, ClassMetadata<object>> $metadata */
3833
$metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
3934

40-
if (count($metadata) === 0) {
41-
throw NoMappingFound::new();
42-
}
43-
4435
usort($metadata, static function (ClassMetadata $a, ClassMetadata $b): int {
4536
return $a->getTableName() <=> $b->getTableName();
4637
});

lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ protected function configure(): void
7575
'all-or-nothing',
7676
null,
7777
InputOption::VALUE_OPTIONAL,
78-
'Wrap the entire migration in a transaction.'
78+
'Wrap the entire migration in a transaction.',
79+
'notprovided'
7980
)
8081
->setHelp(<<<EOT
8182
The <info>%command.name%</info> command executes a migration to a specified version or the latest available version:

lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,26 @@ public function getMigratorConfiguration(InputInterface $input): MigratorConfigu
2121
{
2222
$timeAllQueries = $input->hasOption('query-time') ? (bool) $input->getOption('query-time') : false;
2323
$dryRun = $input->hasOption('dry-run') ? (bool) $input->getOption('dry-run') : false;
24-
$allOrNothing = $input->hasOption('all-or-nothing') ? $input->getOption('all-or-nothing') : null;
25-
$allOrNothing = (bool) ($allOrNothing ?? $this->configuration->isAllOrNothing());
24+
$allOrNothing = $this->determineAllOrNothingValueFrom($input) ?? $this->configuration->isAllOrNothing();
2625

2726
return (new MigratorConfiguration())
2827
->setDryRun($dryRun)
2928
->setTimeAllQueries($timeAllQueries)
3029
->setAllOrNothing($allOrNothing);
3130
}
31+
32+
private function determineAllOrNothingValueFrom(InputInterface $input): ?bool
33+
{
34+
$allOrNothingOption = null;
35+
36+
if ($input->hasOption('all-or-nothing')) {
37+
$allOrNothingOption = $input->getOption('all-or-nothing');
38+
}
39+
40+
if ($allOrNothingOption === 'notprovided') {
41+
return null;
42+
}
43+
44+
return (bool) ($allOrNothingOption ?? true);
45+
}
3246
}

tests/Doctrine/Migrations/Tests/Configuration/EntityManager/_files/em-loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public function getEntityManager(?string $name = null): EntityManagerInterface
1919
$conf->setProxyNamespace('Foo');
2020
$conf->setMetadataDriverImpl(new PHPDriver(''));
2121

22-
return EntityManager::create($conn, $conf);
22+
return new EntityManager($conn, $conf);
2323
}
2424
};

tests/Doctrine/Migrations/Tests/Configuration/EntityManager/_files/migrations-em.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
$conf->setProxyNamespace('Foo');
1515
$conf->setMetadataDriverImpl(new PHPDriver(''));
1616

17-
return EntityManager::create($conn, $conf);
17+
return new EntityManager($conn, $conf);

tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Doctrine\ORM\EntityManagerInterface;
1313
use Doctrine\ORM\Mapping\Driver\XmlDriver;
1414
use Doctrine\ORM\ORMSetup;
15-
use UnexpectedValueException;
1615

1716
/**
1817
* Tests the OrmSchemaProvider using a real entity manager.
@@ -37,10 +36,14 @@ public function testCreateSchemaFetchesMetadataFromEntityManager(): void
3736
}
3837
}
3938

40-
public function testEntityManagerWithoutMetadataCausesError(): void
39+
/**
40+
* It should be OK to use migrations to manage tables not managed by
41+
* the ORM.
42+
*
43+
* @doesNotPerformAssertions
44+
*/
45+
public function testEntityManagerWithoutMetadata(): void
4146
{
42-
$this->expectException(UnexpectedValueException::class);
43-
4447
$this->config->setMetadataDriverImpl(new XmlDriver([]));
4548

4649
$this->ormProvider->createSchema();
@@ -52,7 +55,7 @@ protected function setUp(): void
5255
$this->config->setClassMetadataFactoryName(ClassMetadataFactory::class);
5356

5457
$this->conn = $this->getSqliteConnection();
55-
$this->entityManager = EntityManager::create($this->conn, $this->config);
58+
$this->entityManager = new EntityManager($this->conn, $this->config);
5659
$this->ormProvider = new OrmSchemaProvider($this->entityManager);
5760
}
5861
}

tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public function testExecuteMigrateDown(): void
362362
}
363363

364364
/**
365-
* @psalm-param array<string, bool> $input
365+
* @psalm-param array<string, bool|int|string|null> $input
366366
*
367367
* @dataProvider allOrNothing
368368
*/
@@ -390,13 +390,22 @@ public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool
390390
}
391391

392392
/**
393-
* @psalm-return Generator<array{bool, array<string, bool>, bool}>
393+
* @psalm-return Generator<array{bool, array<string, bool|int|string|null>, bool}>
394394
*/
395395
public function allOrNothing(): Generator
396396
{
397397
yield [false, ['--all-or-nothing' => false], false];
398+
yield [false, ['--all-or-nothing' => 0], false];
399+
yield [false, ['--all-or-nothing' => '0'], false];
400+
398401
yield [false, ['--all-or-nothing' => true], true];
402+
yield [false, ['--all-or-nothing' => 1], true];
403+
yield [false, ['--all-or-nothing' => '1'], true];
404+
yield [false, ['--all-or-nothing' => null], true];
405+
399406
yield [true, ['--all-or-nothing' => false], false];
407+
yield [true, ['--all-or-nothing' => 0], false];
408+
yield [true, ['--all-or-nothing' => '0'], false];
400409

401410
yield [true, [], true];
402411
yield [false, [], false];

tests/Doctrine/Migrations/Tests/Tools/Console/config/cli-config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
$conn = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]);
1919

20-
$em = EntityManager::create($conn, $conf);
20+
$em = new EntityManager($conn, $conf);
2121

2222
$config = new ConfigurationArray([
2323
'custom_template' => 'foo',

0 commit comments

Comments
 (0)