Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't Prompt the User for Confirmation on the migrations:migrate Command When There is Nothing to Do #480

Merged
merged 7 commits into from
Nov 18, 2016

Conversation

chrisguitarguy
Copy link
Contributor

Possibly closes #306

Couple big things here:

  • Better tests for the MigrateCommand so I could feel more comfortable changing it
  • Moved the "No migrations ..." message into Migration::migrate.
  • Reworked Migration::migrate to take an optional fourth argument for "confirm" the migrations can execute. This is similar to how OuputWriter abstracts away the Symfony console output in Migration. The default behavior is to always "confirm" the migrations if no $confirm callback is given (same as it is currently).

Not sure if adding another argument is okay, but it seemed to make the most sense. Even if none of the changes are okay, I do think the tests for the MigrateCommand are useful. Let me know!

This brings them inline with some of the other, newer command tests that
use Symfony's command tester. There's more coverage as well. Done so
some changes can be made to `MigrateCommand`.
Removes a level of nesting from the rest of the method so some changes
can be a bit nicer later on.
Provides the same output to the user as before.
Provides a way to hook into the migration and ask the user for
confirmation. Right now that happens further up stream in a console
command.
Means there's no longer a big warning or confirmation when no migrations
are to be executed.
@mikeSimonson
Copy link
Contributor

@chrisguitarguy Thanks

It will take a little more time to review that PR for me but don't hesitate to ping me if I don't do it by next week.

@@ -118,12 +118,11 @@ public function setNoMigrationException($noMigrationException = false)
* @param string $to The version to migrate to.
* @param boolean $dryRun Whether or not to make this a dry run and not execute anything.
* @param boolean $timeAllQueries Measuring or not the execution time of each SQL query.
*
* @return array $sql The array of migration sql statements
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep these lines separating params from the return value. It makes things more readable IMO

@dzoeteman
Copy link

@chrisguitarguy @mikeSimonson What's the status on this pull request? This would be an extremely helpful improvement.

@mikeSimonson mikeSimonson self-assigned this Nov 2, 2016
@mikeSimonson
Copy link
Contributor

I will review and merge this tomorrow without fault.

@chrisguitarguy
Copy link
Contributor Author

Let me know if you need anything @mikeSimonson, I kind of lost track of this one.

@chrisguitarguy
Copy link
Contributor Author

Any updates here @mikeSimonson? It's okay to reject too, I know it's a big-ish change.

@mikeSimonson
Copy link
Contributor

@chrisguitarguy As I said my only reserve is the change of the signature of the migrate method to make it return false. What do you think about that ? Wouldn't it be better to make it return an empty array ?

@chrisguitarguy
Copy link
Contributor Author

What do you think about that ? Wouldn't it be better to make it return an empty array ?

I guess I was looking for a way to signify the difference between no migrations being found and the cancel callback failing. This means that the command can exit with a 1 status code if the user cancels.

return array|false is a pretty crappy way to do that, however. Would probably be better to return a value object that iterable to mimic the current pattern and has a method to see whether the migraitons were canceled.

Thoughts?

@mikeSimonson
Copy link
Contributor

Wouldn't you consider returning 0 when the user cancel ? After all there was no error.

@chrisguitarguy
Copy link
Contributor Author

After all there was no error.

That's fair.

I'll make the change tonight!

Because it's not really an error.

This also reworks the console command to keep the same interface:
returns a 1 status code on cancel and outputs "migrations cancelled"
@chrisguitarguy
Copy link
Contributor Author

@mikeSimonson got back to this a bit late, sorry.

I remember why I did the false thing now: it was to keep the same interface that's currently in master.

I reworked Migration::migrate to return an empty arrray and found another way to do that in the console command. Let me know if that works!

*
* @return array $sql The array of migration sql statements
* @return array|false An array of migration sql statements or false if the confirm callback denied execution
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that bothers me in this PR is the return array or false here. Wouldn't it be better if it returned an empty array in this case ? @chrisguitarguy What do you think.

I can make the change tomorrow if you agree to it ?

@mikeSimonson mikeSimonson merged commit 073195c into doctrine:master Nov 18, 2016
@mikeSimonson
Copy link
Contributor

@chrisguitarguy Thanks

@chrisguitarguy chrisguitarguy mentioned this pull request Dec 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Big scary warning when there are actually no migrations to execute.
4 participants