-
Notifications
You must be signed in to change notification settings - Fork 334
Add dump column in schema_migration and sync command line argument #628
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
base: main
Are you sure you want to change the base?
Conversation
…a_migrations table.
|
Applying down migrations is generally a dangerous procedure that results in irreversible data loss. Making it too easy to unintentionally perform them through a "synchronize" action feels especially dangerous. The idea of letting an older version of software destroy data used by a newer version seems to me like a foot-gun of epic proportions. If there are others who have actual use cases that require this functionality, they should speak up in favor of this change. I do not, so I'll recuse myself. Thanks for the thorough work on the PR, though. |
|
Yes, the downgrade can expose to loss of data, but in our use case sometimes is necessary. Even if the PR will be rejected your answer @dossy has been useful because I unserstood better how to use down migrations! Because our purpose of the migration is to adapt database to software changes. But we apply down migration for example because a stored procedure isn't compatible with previous versions. Instead for example if a migration add a column, and in that column is present important data, a down migration shouldn't remove that column. It won't use it, but should delete that. Previously instead I've always thought down migrations as the contrary of up migrations. |
I've added 2 new features to dbmate that can be helpful for many.
This column contains the 'down' migration that need to be executed to rollback the applied migrations. This is useful in this scenario:
This command automatically execute all 'up' migrations available in one shot, or rollbacks future migrations found in existing database thanks to the 'dump' column added in schema_migrations.
P.S. In case the current schema_migrations doesn't have the 'dump' column it is added, and it would be empty at the beginning. But if the .sql files provided to dbmate contain the migration versions already applied, dbmate will also populate the 'dump' column accordingly. So it would work also with existing database. If this feature is not used, does not harm.
P.P.S. Works perfectly with MySQL, I tried also to adapt code of others languages, they compile all, but I don't have tested them.