feat: automatic database backup before migrations #1950
Closed
+82
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
It is possible to create a migration that has unintended consequences. Maybe you dropped the wrong column, maybe the index you added was wrong, etc.
Proposed solution
In this PR, I have added a configuration option that allows you to automatically run a backup before migrations are run. We default this to only running in the environment called
production, although this is also configurable (in cases where the production environment is called something else).We listen for the
MigrationsStartedevent that Laravel broadcasts prior to actually running any new migrations and do a DB-only backup to ensure that any destructive changes can be reverted.The configuration is set to off by default so that users with large databases don't immediately see larger migration times without opting in to the feature.