Skip to content

Commit

Permalink
Merge pull request #1305 from agustingomes/deprecate-all-or-nothing-o…
Browse files Browse the repository at this point in the history
…ptions

Deprecate using `--all-or-nothing` with values
  • Loading branch information
greg0ire authored Oct 11, 2023
2 parents 024b307 + 799f16d commit 42a0111
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
9 changes: 9 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Upgrade to 3.6

## Console
- The `--all-or-nothing` option for `migrations:migrate` does not accept a value anymore, and passing it a
value will generate a deprecation. Specifying `--all-or-nothing` will wrap all the migrations to be
executed into a single transaction, regardless of the specified configuration.



# Upgrade to 3.1

- The "version" is the FQCN of the migration class (existing entries in the migrations table will be automatically updated).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\Migrations\Tools\Console;

use Doctrine\Deprecations\Deprecation;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\MigratorConfiguration;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -28,16 +29,30 @@ public function getMigratorConfiguration(InputInterface $input): MigratorConfigu

private function determineAllOrNothingValueFrom(InputInterface $input): bool|null
{
if (! $input->hasOption('all-or-nothing')) {
return null;
$allOrNothingOption = null;
$wasOptionExplicitlyPassed = $input->hasOption('all-or-nothing');

if ($wasOptionExplicitlyPassed) {
$allOrNothingOption = $input->getOption('all-or-nothing');
}

$allOrNothingOption = $input->getOption('all-or-nothing');
if ($wasOptionExplicitlyPassed && $allOrNothingOption !== null) {
Deprecation::trigger(
'doctrine/migrations',
'https://github.com/doctrine/migrations/issues/1304',
<<<'DEPRECATION'
Context: Passing values to option `--all-or-nothing`
Problem: Passing values is deprecated
Solution: If you need to disable the behavior, omit the option,
otherwise, pass the option without a value
DEPRECATION,
);
}

if ($allOrNothingOption === 'notprovided') {
return null;
}

return (bool) ($allOrNothingOption ?? true);
return (bool) ($allOrNothingOption ?? false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Configuration\Connection\ExistingConnection;
Expand Down Expand Up @@ -42,6 +43,8 @@

class MigrateCommandTest extends MigrationTestCase
{
use VerifyDeprecations;

private DependencyFactory $dependencyFactory;
private Configuration $configuration;
private CommandTester $migrateCommandTester;
Expand Down Expand Up @@ -340,7 +343,7 @@ public function testExecuteMigrateDown(): void
*
* @dataProvider allOrNothing
*/
public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool $expected): void
public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool $expected, bool $expectDeprecation = true): void
{
$migrator = $this->createMock(DbalMigrator::class);
$this->dependencyFactory->setService(Migrator::class, $migrator);
Expand All @@ -355,6 +358,12 @@ public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool
return ['A'];
});

if ($expectDeprecation) {
$this->expectDeprecationWithIdentifier(
'https://github.com/doctrine/migrations/issues/1304',
);
}

$this->migrateCommandTester->execute(
$input,
['interactive' => false],
Expand All @@ -363,7 +372,7 @@ public function testExecuteMigrateAllOrNothing(bool $default, array $input, bool
self::assertSame(0, $this->migrateCommandTester->getStatusCode());
}

/** @psalm-return Generator<array{bool, array<string, bool|int|string|null>, bool}> */
/** @psalm-return Generator<array{0: bool, 1: array<string, bool|int|string|null>, 2: bool, 3?: bool}> */
public static function allOrNothing(): Generator
{
yield [false, ['--all-or-nothing' => false], false];
Expand All @@ -373,7 +382,7 @@ public static function allOrNothing(): Generator
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 [false, ['--all-or-nothing' => null], false, false];

yield [true, ['--all-or-nothing' => false], false];
yield [true, ['--all-or-nothing' => 0], false];
Expand Down

0 comments on commit 42a0111

Please sign in to comment.