SQLServerCentral Editorial

Is Rollback Feasible for Database Changes?

,

One of the things I used to show people in SQL Compare was the ability to generate a quick rollback script by switching the source and target. We can generate a deployment script going from Dev to Production, switch the source and target, and then generate the rollback script, from Production to Dev. This was the automation of a manual process I used to go through, examining changes made in deployment scripts and producing the reversing changes for various schema items.

Really the only object that causes us problems is the table. We can easily grab previous versions of views, functions, stored procedures and other code objects, applying them on top of our deployment without worrying about maintaining state. We can go back and forth with different versions of code. Certainly our applications might have issues, but the database itself works fine and deployment is quick.

However, that's not the case for tables. If I add a column to a table in a deployment, how do I remove it? Certainly I can drop the column, but what happens if there's been a data transformation, or users have entered data? I might need to preserve the data that's been added, which is a process I might not want to script. What if I split a column or refactor data to a new table? The movement of data back to it's original spot, while preserving any changed data, is not a trivial task. Add up enough changes in a deployment and it wouldn't be worth running any rollback scripts. A database restore might be more efficient.

Recently I was discussing these issues with a developer, who remarked that they never built rollback scripts. It wasn't a good use of time. If there were issues, developers or DBAs would need to make decisions about how to handle the issues. These days, as we've become better at architecting database applications, we might even decide to leave the actual table alone and use view or stored procedure change to effect a virtual rollback for the application, erasing the changed schema with code rather than actually returning the table schemas to their previous versions. 

As I see our organizations depending on databases to a larger and larger degree, requiring no more downtime than actually needed, I think that rollback scripts for tables might be a thing of the past. Certainly rolling back object code is still possible, with an understanding of the impact on both the database and application when old code is used. That's definitely a decision that needs to be made on a deployment by deployment basis.

My view is that whenever possible, both the application and database should try to be forward and backward compatible by one version to allow changes to be made to one or the other without breaking the system. That's not always easy, but in many cases it is with a little forethought, practice, and awareness of the architecture techniques that allow this, it can be relatively easy. In some cases, especially with smaller databases or discrete, limited changes, rollback scripts might make sense. However, I think for most of us this is a software development pattern that's not worth considering most of the time.

Rate

4 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

4 (1)

You rated this post out of 5. Change rating