migrations icon indicating copy to clipboard operation
migrations copied to clipboard

Do not allow down migration, if up migration was never run

Open cb0 opened this issue 5 years ago • 3 comments

Feature Request

When running a down migration, that was never migrated up, doctrine should notice that and not try to migrate down.

Q A
New Feature yes
RFC no
BC Break no

Summary

I'm currently using doctrine/migrations version 2.2.0 with Zend.

If by accident someone calls a down script, as written in the text description after migration was generated. e.g.

To revert the migration you can use migrations:execute --down 20191127145240

This will most likely result in an error. In the worst case, the database could result in an inconsistent state.

As all migrations that were executed are stored in the migrations table, it should just check if it was run before. Otherwise, it should result in an error like 'This migration was never not run'.

cb0 avatar Nov 27 '19 15:11 cb0

Thank you for opening this issue. As far as I understand this is an edge case where a user has to set a migration version with --down that wasn't executed before in a migration?

Do you have a suggestion for a fix for a pull request or even want to create one?

SenseException avatar Dec 11 '19 21:12 SenseException

Hi @SenseException,

I thought about checking the Version table and only allow Migration if it is in there. I did create the PR #900 for that issue.

As this is my first PR here I'm not quite sure if I'm missing someting else. And if this will also work for upcoming 3.0.

Please let me know if I should add some other things like tests e.g.

cb0 avatar Dec 29 '19 18:12 cb0

I realised that I did the fix for old 2.X release and therefore the build broke. Changed target again to be 'master' and fixed it in there.

Had to created a new class 'RolldownFailed' as only 'RollupFailed' existed for now.

cb0 avatar Dec 30 '19 17:12 cb0