Skip to content

Commit a3fc5b3

Browse files
authored
Merge pull request #1456 from agustingomes/all-or-nothing-option
Simplify handling of `--all-or-nothing` and `--no-all-or-nothing` options
2 parents bcff5ce + 51d59dd commit a3fc5b3

File tree

6 files changed

+13
-104
lines changed

6 files changed

+13
-104
lines changed

UPGRADE.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# Upgrade to 4.0
2+
3+
## Console
4+
- The `--all-or-nothing` option for `migrations:migrate` does not accept a value anymore, and is now exclusively used
5+
to enable wrapping all migrations in a single transaction. To disable it, you can use the `--no-all-or-nothing`
6+
option instead. Both options override the configuration value.
7+
8+
9+
110
# Upgrade to 3.6
211

312
## Console

docs/en/reference/configuration.rst

-4
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,6 @@ use the ``--all-or-nothing`` option:
250250
251251
$ ./vendor/bin/doctrine-migrations migrate --all-or-nothing
252252
253-
.. note::
254-
255-
Passing options to --all-or-nothing is deprecated from 3.7.x, and will not be allowed in 4.x
256-
257253
To override the configuration and explicitly disable All or Nothing Transaction from the command line,
258254
use the ``--no-all-or-nothing`` option:
259255

src/Tools/Console/Command/MigrateCommand.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Doctrine\Migrations\Exception\NoMigrationsToExecute;
99
use Doctrine\Migrations\Exception\UnknownMigrationVersion;
1010
use Doctrine\Migrations\Metadata\ExecutedMigrationsList;
11-
use Doctrine\Migrations\Tools\Console\ConsoleInputMigratorConfigurationFactory;
1211
use Symfony\Component\Console\Attribute\AsCommand;
1312
use Symfony\Component\Console\Formatter\OutputFormatter;
1413
use Symfony\Component\Console\Input\InputArgument;
@@ -74,15 +73,8 @@ protected function configure(): void
7473
->addOption(
7574
'all-or-nothing',
7675
null,
77-
InputOption::VALUE_OPTIONAL,
76+
InputOption::VALUE_NEGATABLE,
7877
'Wrap the entire migration in a transaction.',
79-
ConsoleInputMigratorConfigurationFactory::ABSENT_CONFIG_VALUE,
80-
)
81-
->addOption(
82-
'no-all-or-nothing',
83-
null,
84-
InputOption::VALUE_NONE,
85-
'Disable wrapping the entire migration in a transaction.',
8678
)
8779
->setHelp(<<<'EOT'
8880
The <info>%command.name%</info> command executes a migration to a specified version or the latest available version:

src/Tools/Console/ConsoleInputMigratorConfigurationFactory.php

+3-50
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Doctrine\Migrations\Tools\Console;
66

7-
use Doctrine\Deprecations\Deprecation;
87
use Doctrine\Migrations\Configuration\Configuration;
98
use Doctrine\Migrations\MigratorConfiguration;
109
use Symfony\Component\Console\Input\InputInterface;
@@ -31,55 +30,9 @@ public function getMigratorConfiguration(InputInterface $input): MigratorConfigu
3130

3231
private function determineAllOrNothingValueFrom(InputInterface $input): bool|null
3332
{
34-
$enableAllOrNothingOption = self::ABSENT_CONFIG_VALUE;
35-
$disableAllOrNothingOption = null;
36-
37-
if ($input->hasOption('no-all-or-nothing')) {
38-
$disableAllOrNothingOption = $input->getOption('no-all-or-nothing');
39-
}
40-
41-
$wasOptionExplicitlyPassed = $input->hasOption('all-or-nothing');
42-
43-
if ($wasOptionExplicitlyPassed) {
44-
/**
45-
* Due to this option being able to receive optional values, its behavior is tricky:
46-
* - when `--all-or-nothing` option is not provided, the default is set to self::ABSENT_CONFIG_VALUE
47-
* - when `--all-or-nothing` option is provided without values, this will be `null`
48-
* - when `--all-or-nothing` option is provided with a value, we get the provided value
49-
*/
50-
$enableAllOrNothingOption = $input->getOption('all-or-nothing');
51-
}
52-
53-
$enableAllOrNothingDeprecation = match ($enableAllOrNothingOption) {
54-
self::ABSENT_CONFIG_VALUE, null => false,
55-
default => true,
56-
};
57-
58-
if ($enableAllOrNothingOption !== self::ABSENT_CONFIG_VALUE && $disableAllOrNothingOption === true) {
59-
throw InvalidAllOrNothingConfiguration::new();
60-
}
61-
62-
if ($disableAllOrNothingOption === true) {
63-
return false;
64-
}
65-
66-
if ($enableAllOrNothingDeprecation) {
67-
Deprecation::trigger(
68-
'doctrine/migrations',
69-
'https://github.com/doctrine/migrations/issues/1304',
70-
<<<'DEPRECATION'
71-
Context: Passing values to option `--all-or-nothing`
72-
Problem: Passing values is deprecated
73-
Solution: If you need to disable the behavior, use --no-all-or-nothing,
74-
otherwise, pass the option without a value
75-
DEPRECATION,
76-
);
77-
}
78-
79-
return match ($enableAllOrNothingOption) {
80-
self::ABSENT_CONFIG_VALUE => null,
81-
null => true,
82-
default => (bool) $enableAllOrNothingOption,
33+
return match ($input->hasOption('all-or-nothing')) {
34+
true => $input->getOption('all-or-nothing'),
35+
default => null,
8336
};
8437
}
8538
}

src/Tools/Console/InvalidAllOrNothingConfiguration.php

-16
This file was deleted.

tests/Tools/Console/Command/MigrateCommandTest.php

-25
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use Doctrine\Migrations\Tests\Helper;
2727
use Doctrine\Migrations\Tests\MigrationTestCase;
2828
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand;
29-
use Doctrine\Migrations\Tools\Console\InvalidAllOrNothingConfiguration;
3029
use Doctrine\Migrations\Version\AlphabeticalComparator;
3130
use Doctrine\Migrations\Version\ExecutionResult;
3231
use Doctrine\Migrations\Version\MigrationFactory;
@@ -377,38 +376,14 @@ public function testExecuteMigrateAllOrNothing(bool|null $default, array $input,
377376
/** @psalm-return Generator<array{0: bool|null, 1: array<string, bool|int|string|null>, 2: bool, 3?: bool}> */
378377
public static function allOrNothing(): Generator
379378
{
380-
yield [false, ['--all-or-nothing' => false], false];
381-
yield [false, ['--all-or-nothing' => 0], false];
382-
yield [false, ['--all-or-nothing' => '0'], false];
383-
384-
yield [false, ['--all-or-nothing' => true], true];
385-
yield [false, ['--all-or-nothing' => 1], true];
386-
yield [false, ['--all-or-nothing' => '1'], true];
387379
yield [false, ['--all-or-nothing' => null], true, false];
388380
yield [true, ['--no-all-or-nothing' => null], false, false];
389381

390-
yield [true, ['--all-or-nothing' => false], false];
391-
yield [true, ['--all-or-nothing' => 0], false];
392-
yield [true, ['--all-or-nothing' => '0'], false];
393-
394382
yield [true, [], true, false];
395383
yield [false, [], false, false];
396384
yield [null, [], false, false];
397385
}
398386

399-
public function testThrowsOnContradictoryAllOrNothingOptions(): void
400-
{
401-
$this->expectException(InvalidAllOrNothingConfiguration::class);
402-
403-
$this->migrateCommandTester->execute(
404-
[
405-
'--all-or-nothing' => null,
406-
'--no-all-or-nothing' => null,
407-
],
408-
['interactive' => false],
409-
);
410-
}
411-
412387
public function testExecuteMigrateCancelExecutedUnavailableMigrations(): void
413388
{
414389
$result = new ExecutionResult(new Version('345'));

0 commit comments

Comments
 (0)