-
Notifications
You must be signed in to change notification settings - Fork 611
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
[5.x]: Restoring a database backup after a failed migration leaves newly created tables around #14987
Comments
Thanks for pointing that out! Normally migrations will explicitly delete tables they’re about to create, if they happen to already exist, but we overlooked that for a couple tables. Fixed for the next release. |
Craft 5.1.3 is out with that fix. Thanks again. |
@brandonkelly Thanks! Still, couldn't the restoration be handled better by the migrate command itself? I think I recall having the same problem with some plugin migrations … wouldn't it make sense for the migrate command to restore the original state from the DB backup exactly? |
The And similarly, we can’t do it from |
@brandonkelly Not sure I understand the problem 🤔 The This just finds and drops all database tables, then restores the database backup. Why couldn't the |
Sorry, you’re right, |
@brandonkelly Hm, when |
What happened?
Description
I got an error when running all the pending migrations for the Craft 5 upgrade using
php craft up
. The actual error was related to a plugin and not important here. The CLI command then asked whether I wanted to restore the database backup created by the command before running the migrations. I did that, then fixed the problem in my code that caused the migration to fail.Then I ran
php craft up
again, but this time I got this error:Checked the migration in question – this one creates the
elements_owners
table, so it was created during the first attempt at running migrations, but not deleted when restoring the database backup.Steps to reproduce
php craft up
, answering yes when asked whether you want to create a database backup and whether you want to restore that backup after the migration fails.Expected behavior
If I restore a database backup after a failed migration, I expect the database to be restored to the exact state as before that migration. I don't expect tables that were created before the error occurred to stick around, causing additional errors. I would expect to be able to run migrations again, without additional errors due to the first attempt.
Actual behavior
Tables created during the failing migration (or any previous migration) stick around, even when the database backup is restored.
The
db/restore
command explicitly asks whether to drop all tables before restoring the backup. Themigrate/up
command should do this as a default. It could also add the same prompt asking whether I want to drop all tables before restoring the backup, though I can't see any case where I wouldn't want this behaviour.Craft CMS version
5.1.2
PHP version
8.2
Operating system and version
No response
Database type and version
MySQL
Image driver and version
No response
Installed plugins and versions
The text was updated successfully, but these errors were encountered: