Home » Uncategorized

Should Database Design Be Incremental?

29 December 2003 1,028 Views No Comment

When developing a new system that is not in production, database design can easily be incremental without much thought. In production systems, however, changes to the database are not as pleasant.

If the database is an interface point between multiple systems, it seems like its worth spending the time to sit down with all involved parties and hammer out the database schema in an upfront fashion. Of course, this doesn’t eternally prevent changes to the database, but it can help standardize an interface. Another approach to standardization of a database-based interface is to use a view, a separate table, or a separate database. Then any database changes that are made to the system must be updated in the mapping that creates the interface (e.g. the view must be updated).

Here are the main types of changes that I have come across and how I’ve handled them:

Changes to the application, no changes to the database

Code changes

Data Changes

Schema Changes

Field name changes

Added fields

Removed fields

Datatype changes

Fields moved to other tables (usually when normalizing)

It’s schema changes that make it difficult when in production. Here are the steps that you have to take when you make changes to the schema:

  • Compare your repository to the label from your last release to production and determine exactly what has changed in your database creation scripts (your scripts should always be updated with any changes you make during development)
  • Write a database migration script that will move your data from the old schema to the new schema
  • Take a snapshot of your production database and load it onto your staging server
  • Test run your script
  • Freeze your production database
  • Back up your (pre-migrated) production data
  • Copy your frozen production database to your staging server
  • Rerun your script on your staging server (to make sure that all the new data that was introduced since your first test run still gets migrated correctly)
  • Run your script in production
  • Back up your (post-migrated) production data
  • Unfreeze your production database

  • Leave your response!

    Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

    Be nice. Keep it clean. Stay on topic. No spam.

    You can use these tags:
    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.