Performance: Changing column types
MEDIUM IMPACT
This affects page load speed indirectly by impacting database query performance and server response time, which can delay rendering of data-driven pages.
class ChangeColumnTypeGood < ActiveRecord::Migration[7.0] def up add_column :users, :age_new, :string execute('UPDATE users SET age_new = age::text') remove_column :users, :age rename_column :users, :age_new, :age end def down # reverse steps end end
class ChangeColumnTypeBad < ActiveRecord::Migration[7.0] def change change_column :users, :age, :string end end
| Pattern | Database Locking | Query Speed | User Impact | Verdict |
|---|---|---|---|---|
| Direct change_column | Full table lock | Slow during migration | Page load delays, downtime | [X] Bad |
| Add new column + backfill | Minimal locking | Fast queries after migration | Minimal downtime, faster page loads | [OK] Good |