I am working on some schema changes to an existing database.
I backed up the database to get a dev copy, and have made my changes. I will be creating a single roll script to migrate the changes on the production machine in a single transaction.
Is there a best practice for creating a rollback script encase a deployment issue arises? Before I’ve written then by hand using the following pattern:
- Drop new constraints and indexes
- Alter tables to remove new columns
- Drop added tables
- Commit transaction
Is there a better approach?
That’s basically it, I don’t think there’s much to add, aside from what your approach. This is how we do it in our company, we developers are responsible for creating the script and the rollback script, and we are responsible for leaving the DB in the same state it was before the initial changes are applied. Then the DBAs run it in production, if there’s ever a problem they’ll run the rollback script and everything is back to normal. Just keep in mind the dependencies and the order in which you alter your objects and then create the rollback script backwards.