Skip to content

Commit

Permalink
Merge pull request #1299 from doctrine/3.5.x-merge-up-into-3.6.x_HpL0…
Browse files Browse the repository at this point in the history
…fw1G
  • Loading branch information
greg0ire authored Jan 11, 2023
2 parents 7fa9d14 + 01f89a1 commit 53303eb
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand All @@ -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
Expand Down Expand Up @@ -81,7 +81,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"
/>
Expand All @@ -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"
},
Expand Down Expand Up @@ -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. |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
Expand Down
9 changes: 0 additions & 9 deletions lib/Doctrine/Migrations/Provider/OrmSchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

/**
* @throws NoMappingFound
*/
public function createSchema(): Schema
{
/** @var array<int, ClassMetadata<object>> $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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<<<EOT
The <info>%command.name%</info> command executes a migration to a specified version or the latest available version:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
$conf->setProxyNamespace('Foo');
$conf->setMetadataDriverImpl(new PHPDriver(''));

return EntityManager::create($conn, $conf);
return new EntityManager($conn, $conf);
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function testExecuteMigrateDown(): void
}

/**
* @psalm-param array<string, bool> $input
* @psalm-param array<string, bool|int|string|null> $input
*
* @dataProvider allOrNothing
*/
Expand Down Expand Up @@ -390,13 +390,22 @@ public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool
}

/**
* @psalm-return Generator<array{bool, array<string, bool>, bool}>
* @psalm-return Generator<array{bool, array<string, bool|int|string|null>, 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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 53303eb

Please sign in to comment.