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
Database Downgrade #109
Comments
From axel.fontaine.business@gmail.com on September 20, 2012 07:19:30 What real world use case do you have for downgrades? Please describe so I can better understand your situation. Please note that rolling back a failed migration is not a valid case, as I described here: http://code.google.com/p/flyway/wiki/FAQ#What_about_downgrade_scripts/downward_migrations? Thanks |
From wolfgang...@gmail.com on September 20, 2012 07:45:49 the situation is as follows: As long as you we in development, there is usually no need to do so. But when we go to production we are usually installing the new version, holding back the previous version and just switching from the old to the new version whith the ability to switch back to the previos version in case of unforeseen problems. That I have to care about my migration scripts myself is clear, but that's not the point here (and I think, when my migration script fails, I shouldn't expect my revert script to succeed :-)) Greetings, Wolfgang |
From axel.fontaine.business@gmail.com on September 20, 2012 08:12:25 thanks for your infos. How do you handle drops? Or information destruction in general? And if you make home-made backups, when do you get rid of them? And how well are they tested? There is another approach which I find vastly superior: backwards-compatible upgrades. This way both new and old code can work with the DB at the same time. And if the new code doesn't work, just revert to the old one. There is strictly no impact. Yes, it takes a bit more discipline and might require compatibility views or triggers or leaving older columns around until the old software has been decommisioned. But in my opinion, it's well worth. Also, if you really want downgrade scripts, Flyway doesn't stop you from writing them. You could then just execute them separately if you need to. Cheers |
From wolfgang...@gmail.com on September 20, 2012 12:13:33 for me, it seem a little bit as if you missed my point... :-) When you change a database, there are a lot fo things to think about, regardless if you migrate to a new version or go back to an old and there definitely be a lot of strategies for all different types of database changes, but this has nothing to do with flyway per se - I can do all that things manually. From my point of view, the question is, how can I use flyway and should I use it? Flyway seems to be great in one direction, but when I need to go back one step, I still have to do that manually, so why then use flyway at all? Don't get me wrong here, we might use it even if it's not perfect for us but I think, it might be in your primary interest to implement the possibility to move in both directions because otherwise you might loose a lot of possible users... To point it again, the question is: Why to learn a new tool that does only support me partially - wouldn't it be easier/better to stick at the current approach that might be harder, but is at least consistent either way you migrate to a new version or go back to a previous state? Greetings, Wolfgang |
From axel.fontaine.business@gmail.com on September 20, 2012 13:03:16 no worries, I did understand your point. There are however a number of use cases which for me seem to invalidate this approach. Maybe you can help me understand how this is not the case. How do you rollback drops? Cheers |
From wolfgang...@gmail.com on September 20, 2012 21:55:44 I hope that I understand your point - you mean there are situations where it is not possible to roll back in a completely consistent way, mainly when you drop 'living' data that is not just static and can't be easily converted from one direction to the other because it is modified in the meantime. So if I got you right, you think that reverting a version brings up additional problems. This is not true. What you are doing, is you bring a database from one state to another. The direction you are doing this doesn't matter. It's just a transition. And when you are not a human and just a machine, there are no directions back and forth... Regarding the backups of a table for a revert: I would get rid after I reverted a version (so when I migrate to a new version, I would first do the backups, and when I revert to a previous version I would delete the backups at the end) Greetings, Wolfgang |
+1 |
A standard way to downgrade should be supported even if there are many cases where you can't really undo a migration in that the state of db will not be same as before the migration. The issue is there ARE many scenarios where you can so why not provide that option? Perhaps it can be something else besides a downgrade to imply it is not truely a guaranteed rollback to a prior version. We have to have rollback scripts for every migration in our current projects in order for the DBA to approve them. If there is no feasible rollback for something like a DML script updating a bunch of rows where the prior value is not known, then the rollback can be marked so a warning is produced saying it is not a 100% revert. So if we use Flyway, we would have to grow our own folder conventions and procedures which is enough to discourage us from adopting it. |
Indeed Axel, it sounds like you're arguing that because there are use cases where down migrations fail, it's never helpful. Also, when developing migrations in flyway I often found myself managing the schema_versions table and running down migrations manually. Now I've resorted to calling the migration scripts with \i in psql within an uncommited tranasction to test. |
This feature request doesn't make sense and might cause more problems. Let me give you an example: Now suppose you need to install (lets suppose you want to stay at V14) your project in a new PRD server, or a new testing server, or that you have a new developer in the team and he needs to create his DB. What scripts are going to run on this new install? I'm not even considering to always run all the "upgrade" scripts and then the "downgrade", this is a complete mess (it looks almost the same as the backwards-compatible upgrades, but with some problems). And how would you fix your V15? would you modify the script? This is a shoot in the foot, forget it. Flyway as it is now lets you re-create your DB ALWAYS with the EXACT same steps, don't change this. |
I'll add my thoughts on this, since my team would have been benefited by an automated downgrade quite often. Too many times we had to downgrade manually and that's way too error prone. The need to downgrade
Not everything can be downgradedThis is true in the general case. But in the real world, we have about one such case in 100. The 99 downgrade scripts would have proved quite useful. I bet that people who use Flyway in production can testify to similar percentages - there are very few cases in the real world where an upgrade script cannot be rolled-back/downgraded. Testing downgrade scriptsIt's true that the upgrade scripts will be tested a lot more than the downgrade scripts. But even here Flyway can provides some support. You can have a "test-downgrades" command that applies all the downgrade scripts down to a given version and then re-apply the upgrade scripts to the version from which we downgraded. After this, the developer can just run automated and manual tests to check if everything is still fine. Presumably this can be done just prior to merging the feature branch into the CI branch. @cunhaax So Axel, what do you think? Is there any chance of seeing something like this soon? :) Things look a bit different in real-world usage, and this feature would prove very useful. |
We use flyway a lot in our company and I'd like to vote +1 for "downgrade" feature. Though downgrades is mostly used during developing phase (switching between branches or for wrong migrations - the same as cvmocanu wrote about) the need to do it manually now is not ideal way and at least causes developers to ask questions like "why wasn't it implemented in flyway yet" Thank you |
I'd like to add another voice to the request for rollback. This would be extremely useful for our company as well and is what is preventing our adoption of it here. You may want to "argue" that our use case isn't valid, but that isn't helpful. Further, the use case for us isn't developer convenience, rather to support production. We have a similar use case as mentioned above. When rolling out to production, we'll do the following:
Restoring the old services means that we may have to restore the old database schema. For destructive forward changes such as dropping a column, we can write our migrations to save that column's data off to the side in case we need to rollback (if the data is worthy of being retained). We do this instead of doing a general full backup of the database during this window in the advent of a need to rollback the migration. Our database is too large for the window to do a full backup and do all the other checks. The point is, rollback is needed not because there is an issue with the migrations themselves, but because of an operational need. Something not due to the DB or sometimes even the software itself. The above is incomplete in all the reasons as to why we need to roll the schema back and it is certainly not meant to be an airtight argument for why we need it. For instance, someone might read this and rather than attempting to understand the use case, might instead choose to argue its validity. Such a person might state that one doesn't need to "rollback the schema" when switching back to a previous version of a service. The truth is that many times you can make the schema backwards compat with an older version, but sometimes you can't. This isn't about arguing whether rollbacks can fail - of course they can - so can rolling forward. That's not the point. We want to avoid manual steps during production roll out and need to handle both satisfactory rollouts and emergency rollbacks in the case something major prevents the rollout. |
@sfmontyo You have described exactly my case. +1 |
@flyway if we have an upgrade scripts, we must have downgrade ones |
Several years later and I'm at a new job and have same situation again... cannot adopt flyway without structured downgrades or rollbacks. Is this a scenario justifying a fork in the project? |
Another use-case that needs support for a downgrade feature is in development environments where a single developer may be working on different features, with each feature being on a different Git feature branch. If one of those feature branches involves adding a field to a table in their local database, then once that migration is applied to their local DB they can't work on any other feature branches until that migration is applied in all branches (since the other branches wouldn't have the new migration, but the local database would, flyway would throw an error). Now there is obviously the issue of drops and/or deletes to deal with, but there are ways of handling that (many other DB migration tools for other environments, like Ruby on Rails, already do). Of course there is the counter-argument that support for downgrading migrations causes more problems than it solves, and in some cases that is true. However, a developer who has to work on multiple feature branches should not have to drop their entire database schema and let flyway recreate it every time they want to switch feature branches. Many times developers enter in data while they are working on a feature for testing and/or debugging purposes, and they shouldn't have to always lose all of that data when switching branches. Now obviously the developer is just going to have to deal with having to re-enter some data when switching branches (for whatever field was added/deleted), but they shouldn't have to re-enter data that wasn't affected by the database migration. Flyway should support downgrade scripts, as this is a valid and common use case (and many other ones were mentioned on this thread as well) that requires downgrade script support. |
Any news on this? Changing branches is also a big reason why I need rollbacks. Especially since we are using a feature-branch + rebase workflow. To support this, it would be nice for Flyway to rollback and migrate automatically, like this:
This should be an option so we can activate it in development only. Don't get me wrong. Flyway is a wonderful tool, and I push for its usage in all the projects I can. But without rollback it feels half implemented. |
+1 on support for rollbacks/downgrades |
+1, especially as the need for downgrade would increase if Condensed Migrations are supported (#470). Testing Condensed Migrations would be much easier if downgrade is supported. |
+1, I also have encountered issues with this feature not being available. I've actually always created an downgrade script for all my migration scripts which return the DB to its previous state. I have never encountered an issue where a downgrade script could not be created (though, in some cases, a little forethought is required). A downgrade is needed in a number of cases. Just as a few examples, if v10 is our live version, and we have migrated v11 & v12 to our test server - but then find a production bug which needs to be addressed right away (v11&v12 will not be ready for months). We need to downgrade our test server back to v10 in order for the code to be compatible with the bug-fix code and be tested. Or if I have v12 on our test server, and I create v13. It works for me locally, but fails for some external reason when v13 is migrated to the test server. This shouldn't ever happen, but it can. Once I have a possible fix to v13, it would be nice to be able to downgrade to v12 locally, then re-migrate v13 to insure it still works as expected locally before having the script re-attempted on the test server. All of this could be done by doing a clean & migrate, but this might be a very slow process. |
+1 ; in the real world there are many cases where this is very useful even if in theory this is not possible all the time. Just make is as "use at your own risk" feature. this could be quite simple (by having using a naming convention for example extention=.reverse.sql or something) I'm trying to make it work by using alternative scripts location and schema_version table, but I'm a bit stuck with running scripts in the reverse order. Is that possible? If so there could be a workaround without any dev required. |
+1 We also see the lack of downgrade possibility, escpecially on development. I was little suprised, when I realized that the leading database migration framework for Java does not support downgrades, when frameworks for other programming languages support it for years (e.g. for Python). |
+1 The documentation is a good start to understand how it works and maybe port it to Flyway: |
+1 for downgrade, but -1 for using same files for migration and downgrade. It may be fine for RoR Active Record migrations, but not for general purpose DB upgrade tool like Flyway. You would need some DSL to embed SQLs in it to support the same files, but much better is to avoid it and have plain SQL in the migration scripts and differentiate downgrade through file or directory names, like Flyway is doing now for migration ordering. |
@mcekovic it's true that having to deal with a specific DSL is not ideal. I like your idea of having a different folder or filename pattern but it might be difficult to see the connection between a migration and its reverse especially in the case of a separate folder. Another options could be to do like the Play evolutions which are plain SQL with a part for Ups and a part for Downs (Separated by special comments): https://www.playframework.com/documentation/2.5.x/Evolutions. |
+1 for the downgrade feature. I have seen various projects facing the same problem ever and ever again. And some times there were solutions that were extremely helpful during development and production as it has already been pointed out. So i vote strongly for introducing also a downward migration functionality in flyway because it simply matches the current needs of any developer and/or company that wants to work professionally. My suggestion:
So you would have like:
The only thing flyway needs to do is to take care of the versioning table. All the other things are developer problems. |
I am having trouble understanding why Flyway has such a hostility towards rolling back migrations*. It's not an acceptable solution to say "just snapshot your production database and go back to that if something terrible goes wrong". What about all the data created since then? What if we already designed the application to be forward compatible? Let the application owner make these decisions and the software support them however it can. It's true, it's uncommon and unwise to rollback migrations on a production database. But it's extremely common to do so during testing and development. Especially when dealing with multiple branches. I understand Flyways reasoning for promoting it as a bad idea. However, any reasoning you can think off is immediately dismissed by developers who understand those issues and risks and have successfully used rollback migrations in other platforms. |
@elliotchance Cannot agree more! |
Yes, I need this during development! |
Yes, database downgrade would be a feature mostly used in development environments (or Integration, QA, UAT, Performance testing environments), and probably very rarely in production, so argument about 'not suited for production' does not hold. But, on the other hand, why not in production? Some database downgrades can be dangerous or hard or time consuming to be applied in production (like downgrade for remove column migration, where old column with data needs to be restored), but some database downgrades are fully safe (like rename column or table). Ether case, Database Downgrade paired with Condensed Migrations are a must have features for serious database Continuous Delivery process on mission-critical multi-million record RDBMSes. |
+1 for the downgrade feature. Please do not mix up rollback of failing migration and downgrade use case. They are completely different!!! I must admit, that this is the only one issue, that I miss in flyway. For each version our developers always prepare two scripts: one for upgrade and one for downgrade. Yes, we're aware that complete downgrade of data is not always possible but this is not the issue of tool, but issue of data backups. And this happens really rare, not more that 1 of 10 upgrades. My proposal for this feature implementation would be the following: Configuration
Default values could be: UsageThe usage without option
That's it, from my point of view there is not a lot of work to be done, to make many DB Administrators happy. |
Forward and reverse database migrations have been in every software product I have developed. It is essential for a number of use cases.
This is pretty much what everyone else said. I am considering using flyway. I need rollbacks. |
This is great news. |
Thank you, great news! |
@axelfontaine Can you please clarify how |
@cowwoc I have now added a new section to the docs for this: https://flywaydb.org/documentation/migration/#undo-migrations |
@axelfontaine Interesting. How does one associate an UNDO migration to an SQL migration file? I assume these sit alongside the versioned SQL migrations with a different filename prefix? |
@cowwoc I have now clarified this both in the docs (https://flywaydb.org/documentation/migrations#naming) and a new tutorial (https://flywaydb.org/getstarted/undo). See also https://flywaydb.org/documentation/commandline/migrate#undoSqlMigrationPrefix |
@axelfontaine Looks good to me. Thank you! |
Original author: wolfgang...@gmail.com (September 20, 2012 07:06:48)
I am new to flyway and currently evaluating how/if we could use flyway in our project.
What I really miss, is the possibility to downgrade a database to a previous version. Migrating to the newest version is fine when you start from scratch and when you have no (production) data in a database. But in the case you have to step back you still have to do everything manually.
In my opinion, this would not very hard to implement. You just have to provide some additiona scripts with a __dowgrade suffix that revert a certain version and do the things you did from the other direction.
At the moment, this is the main issue regarding use/don't use flyway. Stepping back seems to be still clumsy and when it is necessary to do a downgrade manually, the question arises to do the migration manually also to be consistent.
Original issue: http://code.google.com/p/flyway/issues/detail?id=334
The text was updated successfully, but these errors were encountered: