1. Concept library
  2. Backend with Node.js
  3. Module 6: Data access layers

Concept

Migrations

A migration is a versioned script that changes the schema, applied in order on every environment. It makes the database's shape part of the code, reviewed and deployed with it.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain what a migration is and why applied ones are immutable
  2. Write a migration that adds a table and one that changes a column
  3. Spot the edited migration that other environments never see

In practice

A few lines that show Migrations doing its job.

SQL
-- migrations/0007_orders_note.sql
ALTER TABLE orders ADD COLUMN note text;

-- A safe rename is two deploys:
-- 1. add the new column, write to both, backfill
-- 2. switch reads, then drop the old column

The common mistake

Watch for

Editing a migration that has already run somewhere. Other environments never see the change; write a new migration instead, and treat applied ones as immutable.

What to know first

Your roadmap puts these before Migrations, unless you already know them.

How it stays learned

Once a session shows you understand Migrations, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Migrations.

Previous in the module← Query builders and ORMs
Next in the moduleTransactions →