doctrine / migrations

Doctrine Database Migrations Library
https://www.doctrine-project.org/projects/migrations.html
MIT License
4.65k stars 386 forks source link

Deprecation always triggers with or without `--all-or-nothing` option #1379

Closed endelwar closed 7 months ago

endelwar commented 7 months ago

Bug Report

Q A
BC Break no
Version 3.7.1

Summary

When running bin/console doctrine:migrations:migrate deprecation for passing values to --all-or-nothing always triggers because option has default value.

Current behavior

Due to https://github.com/doctrine/migrations/pull/1296 a default option for --all-or-nothing is always set ('notprovided'), making check on https://github.com/doctrine/migrations/blob/78484f91fef85f2d579cd0a4a662d77f3b742398/lib/Doctrine/Migrations/Tools/Console/ConsoleInputMigratorConfigurationFactory.php#L33-L34 to always set $allOrNothingOption to a not null value, which then triggers the deprecation:

User Deprecated: 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 (ConsoleInputMigratorConfigurationFactory.php:44 called by ConsoleInputMigratorConfigurationFactory.php:22, https://github.com/doctrine/migrations/issues/1304, package doctrine/migrations) {"exception":"[object] (ErrorException(code: 0): User Deprecated: Context: Passing values to option `--all-or-nothing`\nProblem: Passing values is deprecated\nSolution: If you need to disable the behavior, omit the option,\notherwise, pass the option without a value (ConsoleInputMigratorConfigurationFactory.php:44 called by ConsoleInputMigratorConfigurationFactory.php:22, https://github.com/doctrine/migrations/issues/1304, package doctrine/migrations) at /Users/manuel/Sites/myproject/vendor/doctrine/deprecations/lib/Doctrine/Deprecations/Deprecation.php:210)

How to reproduce

Run bin/console doctrine:migrations:migrate and look at the logs

Expected behavior

I expect no deprecation triggered when not setting the --all-or-nothing option

Proposed solution

Remove the default value of all-or-nothing option in Doctrine\Migrations\Tools\Console\Command\MigrateCommand::configure

greg0ire commented 7 months ago

Cc @agustingomes

greg0ire commented 7 months ago

Proposed solution

Remove the default value of all-or-nothing option in Doctrine\Migrations\Tools\Console\Command\MigrateCommand::configure

Why not instead alter the computation of $wasOptionExplicitlyPassed to see check if the value is notprovided?

stof commented 7 months ago

$input->hasOption('all-or-nothing') does not check at all whether this option was passed. It checks whether this option is defined.

gaetan-petit commented 7 months ago

Isn't as easy as changing notprovided to null in Doctrine\Migrations\Tools\Console\Command\MigrateCommand::configure Or even to remove the default value?

agustingomes commented 7 months ago

@gaetan-petit From my understanding, is not as easy as what you mention because of what @stof mentioned. That complicates the check a bit, as you can see in the PR you have opened with the test case that is failing.

This is what I wrote back when I did the commit adding the notprovided:

This test case addition simulates what happens when the `--all-or-nothing` option is indicated, but no explicit value is passed.

We'll set a default option, which is retrieved in case the option has not been provided, allowing us to override the value in case the option is different than the default value.
agustingomes commented 7 months ago

@endelwar there's a new release available which should have this issue fixed.

endelwar commented 7 months ago

Great work! thanks!