Skip to main content

Command Palette

Search for a command to run...

πŸš› Database Migrations Explained Like You're 5

Published
β€’2 min read
S

Building AI systems and writing about how they actually work. Master of AI @ University of Technology Sydney. Previously B.Tech CS with focus on IoT. I believe the best way to learn is to explain. That's why I'm documenting tech concepts with simple analogies (@sreekarreddy.com). AWS Certified β€’ Azure AI Certified β€’ Neo4j Professional β€’ Google Data Analytics When not coding: exploring Sydney, working on side projects, and teaching tech to anyone who'll listen.

Version control for database schema

Day 127 of 149

πŸ‘‰ Full deep-dive with code examples


The Recipe Card Analogy

Your grandma's recipe evolves:

  • Version 1: Original recipe
  • Version 2: Add a pinch of salt
  • Version 3: Use brown sugar instead of white
  • Each change is recorded and reversible

Database migrations track changes to your database structure!


Why Migrations Matter

Without migrations:

  • "Did we add that column?"
  • "What does the database look like in production?"
  • "How do I set up a new developer's database?"

Everyone's database might be different!


How They Work

Each migration is a file:

Migration 1: Create users table
Migration 2: Add email column to users
Migration 3: Create orders table
Migration 4: Add index on email

Run in order, your database evolves consistently.


Key Features

Forward (up):

  • Apply changes: add column, create table

Backward (down):

  • Undo changes: remove column, drop table

Version tracking:

  • Database knows which migrations have run
  • Only applies new ones

Benefits

  • Consistent β†’ All databases match
  • Repeatable β†’ New developer runs migrations, instant setup
  • Reversible β†’ Mistake? Roll back
  • Auditable β†’ History of all changes

The Workflow

  1. Write migration (add column, change type)
  2. Test locally
  3. Commit to version control
  4. Deploy runs migrations automatically
  5. Production updated safely!

In One Sentence

Database Migrations are versioned scripts that track and apply changes to your database structure, so every environment stays in sync.


πŸ”— Enjoying these? Follow for daily ELI5 explanations!

Making complex tech concepts simple, one day at a time.

More from this blog

esreekarreddy

132 posts