Performance: Creating migrations
MEDIUM IMPACT
This affects the database schema update speed and the initial page load time when the app interacts with the database.
class AddDetailsToUsers < ActiveRecord::Migration[7.0] def change change_table :users do |t| t.text :bio t.integer :age t.boolean :admin, default: false end end end
class AddDetailsToUsers < ActiveRecord::Migration[7.0] def change add_column :users, :bio, :text add_column :users, :age, :integer add_column :users, :admin, :boolean, default: false end end
| Pattern | Database Locks | Migration Time | App Downtime | Verdict |
|---|---|---|---|---|
| Multiple separate add_column calls | Multiple locks | Longer | Higher | [X] Bad |
| Single change_table block with multiple columns | Single lock | Shorter | Lower | [OK] Good |