Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checklist for Database Schema Upgrades

Having to upgrade a database schema makes installing a new release of software a lot trickier. What are the best practices for doing this?

I'm looking for a checklist or timeline of action items, such as

  • 8:30 shut down apps
  • 8:45 modify schema
  • 9:15 install new apps
  • 9:30 restart db

etc, showing how to minimize risk and downtime. Issues such as

  • backing out of the upgrade if things go awry
  • minimizing impact to existing apps
  • "hot" updates while the database is running
  • promoting from dev to test to production servers

are especially of interest.

like image 934
Mark Harrison Avatar asked Aug 27 '08 21:08

Mark Harrison


People also ask

How do I update a SQL schema?

To change the schema of a table by using SQL Server Management Studio, in Object Explorer, right-click on the table and then click Design. Press F4 to open the Properties window. In the Schema box, select a new schema. ALTER SCHEMA uses a schema level lock.

What is schema modification?

What Does Schema Change Mean? A schema change is an alteration made to a collection of logical structures (or schema objects) in a database. Schema changes are generally made using structured query language (SQL) and are typically implemented during maintenance windows.

Does database schema changes very frequently?

Database schema changes are not popular among DBAs, not when you are operating production databases and cannot afford to switch off the service during a maintenance window. These are unfortunately frequent and necessary, especially when introducing new features to existing applications.


2 Answers

I have a lot of experience with this. My application is highly iterative, and schema changes happen frequently. I do a production release roughly every 2 to 3 weeks, with 50-100 items cleared from my FogBugz list for each one. Every release we've done over the last few years has required schema changes to support new features.

The key to this is to practice the changes several times in a test environment before actually making them on the live servers.

I keep a deployment checklist file that is copied from a template and then heavily edited for each release with anything that is out of the ordinary.

I have two scripts that I run on the database, one for schema changes, one for programmability (procedures, views, etc). The changes script is coded by hand, and the one with the procs is scripted via Powershell. The change script is run when everything is turned off (you have to pick a time that annoys the least amount of users for this), and it is run command by command, manually, just in case anything goes weird. The most common problem I have run into is adding a unique constraint that fails due to duplicate rows.

When preparing for an integration testing cycle, I go through my checklist on a test server, as if that server was production. Then, in addition to that, I go get an actual copy of the production database (this is a good time to swap out your offsite backups), and I run the scripts on a restored local version (which is also good because it proves my latest backup is sound). I'm killing a lot of birds with one stone here.

So that's 4 databases total:

  1. Dev: all changes must be made in the change script, never with studio.
  2. Test: Integration testing happens here
  3. Copy of production: Last minute deployment practice
  4. Production

You really, really need to get it right when you do it on production. Backing out schema changes is hard.

As far as hotfixes, I will only ever hotfix procedures, never schema, unless it's a very isolated change and crucial for the business.

like image 91
Eric Z Beard Avatar answered Sep 17 '22 23:09

Eric Z Beard


I guess you have considered the reads of Scott Ambler? http://www.agiledata.org/essays/databaseRefactoring.html

like image 29
neslekkiM Avatar answered Sep 20 '22 23:09

neslekkiM