What's the best way to deprecate a column in a database schema? What's the best way to deprecate a column in a database schema? sql sql

What's the best way to deprecate a column in a database schema?


Maybe you should refactor to use views over your tables, where the views never include the deprocated columns.


"Deprecate" usually means (to me at least) that something is marked for removal at some future date, should not used by new functionality and will be removed/changed in existing code.

I don't know of a good way to "mark" a deprecated column, other than to rename it, which is likely to break things! Even if such a facility existed, how much use would it really be?

So do you really want to deprecate or remove? From the content of your question, I'm guessing the latter.

I have the nasty feeling that you may be in one of those "if I wanted to get to there I wouldn't start from here" situations. However, here are some ideas that spring to mind:

  1. Read Recipes for Continuous Database Integration which seems to address much of your problem area

  2. Drop the column explicitly. In MySQL 5.0 (and even earlier?) the facility exists as part of DDL: see the ALTER TABLE syntax.

  3. Look at how ActiveRecord::Migration works in Ruby. A migration can include the "remove_column" directive, which will deal with the problem in a platform-appropriate way. It definitely works with MySQL, from personal experience.

  4. Run a script against your export to remove the column from the INSERT statements, both column and values lists. Probably quite viable if your DB is fairly small, which I'm guessing it must be if you export and re-import it as described.