We recently had to drop a column in production, from a relatively large (order of 10⁷ records) table.
On modern MySQL setups, dropping a column doesn’t lock the table (it does, actually, but for a relatively short time), however, we wanted to improve a very typical Rails migration scenario in a few ways:
- offloading the column dropping time from the deploy;
- ensuring that in the time between the column is dropped and the app servers restarted, the app doesn’t raise errors due to the expectation that the column is present;
- not overloading the database with I/O.
I’ll give the Gh-ost tool a brief introduction, and show how to fulfill the above requirements in a simple way, by using this tool and an ActiveRecord flag.
This workflow can be applied to almost any table alteration scenario.
Contents:
- …