What if you could change your database structure with just a few lines of code, no sweat?
Why Adding and removing columns in Ruby on Rails? - Purpose & Use Cases
Imagine you have a big spreadsheet and you want to add a new column or remove an old one by hand every time your app's data needs change.
You have to open the file, insert or delete columns, and then make sure all your formulas and data still work perfectly.
Doing this manually is slow and risky.
You might forget to update some formulas or break the data structure.
It's hard to keep track of all changes, especially when many people work on the same data.
Rails migrations let you add or remove columns in your database with simple commands.
This keeps your data structure organized and easy to update.
It also tracks changes so everyone on your team stays in sync.
Open database, run SQL: ALTER TABLE users ADD COLUMN age INTEGER;
class AddAgeToUsers < ActiveRecord::Migration[7.0] def change add_column :users, :age, :integer end end
You can safely and quickly change your database structure as your app grows, without breaking anything.
When you add a new feature like user profiles, you might need to add columns like 'age' or 'bio' to store extra info.
Migrations make this easy and safe.
Manual column changes are slow and error-prone.
Rails migrations automate adding/removing columns safely.
This keeps your database organized and your team coordinated.