For this month’s T-SQL Tuesday, James Anderson’s chosen theme is shipping database changes.
Hoo, boy, have I got some scars to talk about.
I’ve been a developer who had to deploy changes, a DBA who had to deploy other peoples’ changes, an open source maintainer, and even been a software vendor who had to hand other people scripts to deploy in their own environment.
Here’s some of the things I assumed over the years – only to learn the hard way that they weren’t always true:
- The deployment script you were given is the most recent one.
- The deployment script will work.
- The last deployment to the same database finished successfully.
- All of the indexes you deployed last time, still exist.
- If you add a unique constraint or index, the existing data doesn’t already violate that constraint.
- All of the tables you deployed last time, still exist.
- Your tables haven’t been moved into another database, with a view or synonym left behind in its place.
- No one has added columns to your tables.
- If you want to add new tables, views, procs, or functions, someone else won’t have already added an object with that name, but a different purpose.
- No one has added triggers on your tables.
- No one has changed the contents of your stored procedures, functions, or views.
- If your objects have been changed, the business wants you to put them back to your own logic, because they didn’t need whatever business logic they’d injected into your code.
- No one has set up a job to run every 15 minutes, check to see if any changes have been made to their (your) stored procedures, and if so, overwrite them with their own custom business logic.
- No one has encrypted your stored procedures or functions.
- No one has added indexed views, stored procs, or functions with schemabinding atop your tables.
- SQL Server Management Studio won’t crash.
- The account you use for deployment will have permissions to change tables.
- The transaction log file will be large enough to let your transactions finish.
- The data file’s drive will be large enough to let your transactions finish.
- No one else will kick off database changes or jobs at the same time as your deployment.
- No one else from your company is trying to do the same deployment you’re trying to do, to the same server, at the same time.
- No one will kick off a Profiler trace to log every one of your statements.
- If they do start a Profiler trace, they won’t do it from a massively underpowered desktop, thereby slowing your deployment to a crawl.
- At the start of your deployment, no one will have an open transaction that blocks you.
- If there’s an open blocking transaction, your work will be more important than theirs, and you won’t have to wait until theirs finishes.
- If there’s an open blocking transaction, and no one knows whose it is, you will be able to kill it.
- If you kill an open blocking transaction, the rollback will finish before your maintenance window ends.
- No one else will kill your session mid-deployment.
- If your deployment script includes multiple transactions, all of them will succeed.
- The deployment person wouldn’t dream of only highlighting some of it and running it.
- The staff who were supposed to work with you during the deployment will be available.
- The staff, if available at the start of the call, will be available during the entire call.
- The staff won’t come down with food poisoning halfway through the deployment call, forget to mute their home office phone, step into the bathroom, and leave the bathroom door open.
- The available staff will have the necessary permissions to do the deployment.
- The staff assigned to user acceptance testing will be able to complete their work in the time allotted.
- The staff assigned to user acceptance testing won’t say they see a problem that they never saw before during the tests that led up to this deployment.
- Midway through the rollback/undo, the user acceptance staff won’t say, “Wait, my bad, it’s fine, go ahead and keep the changes.”
- No one has added replication, synchronous database mirroring, or synchronous AGs into your database.
- If there’s replication or sync mirroring/AGs, they will not affect the performance of your deployment scripts.
- No one will restart the SQL Server instance during your deployment.
- Your connection to the SQL Server will be steady during the deployment because no one will have scheduled firewall work to be done during the same window.
- No one will restart all of the Active Directory domain controllers at once during your deployment, thereby taking your server offline.
- You will not discover corruption in the database during the deployment.
- You will not be blamed for that corruption.
- If you need to do a rollback, the rollback/undo script works with the edge case you ran into during the deployment.
- In the event of a deployment problem, there will be valid backups for rollback.
- Someone who has the permissions and power to do the restore will be available.
Database deployments remind me of the old saying:
In theory, in theory and in practice are the same.
In practice, they are different.