MODULE 05 · DATABASE & SQL

Migration

A database migration is a controlled and versioned change to a database schema or data structure.

01 · What is it?

A migration is a named, ordered change that moves a database from one known state to another.

The change is recorded in source control so a team can apply the same database evolution consistently in development, test, and production.

02 · Think of it like...

Think of a migration like a numbered instruction in a building’s renovation log.

Instead of rebuilding the whole building, the crew applies the next approved instruction: add a room, strengthen a wall, or move a doorway.

Schema v1
Migration 002
Schema v2

03 · What does it do?

Migrations give database changes a repeatable delivery process.

Change Structure

Add tables, columns, indexes, or constraints.

Version Changes

Record which database state the system expects.

Apply Safely

Run an ordered change with review and deployment checks.

Move Data

Transform existing records when the new structure needs it.

04 · Where is it used?

Migrations are used whenever an application’s stored data model needs to evolve.

New FeaturesNew table

Create storage for a new product capability.

Data QualityNew constraint

Require valid values or enforce a relationship.

PerformanceNew index

Make a frequent query faster without changing its meaning.

Release DeliveryEnvironment parity

Keep development, test, and production schemas aligned.

05 · Example

-- migration 002: add order status
ALTER TABLE orders
  ADD COLUMN status VARCHAR(20)
  NOT NULL DEFAULT 'pending';

CREATE INDEX idx_orders_status
  ON orders(status);
  1. The migration file is reviewed and committed.
  2. A migration runner applies it once to each environment.
  3. Existing orders receive the safe default value.
  4. New code can now read and update orders.status.

The application code and the database schema move forward together as one release.

06 · How it connects

Source Control
Migration File
Migration Runner
Database Schema
Application

A migration connects a code change to the stored data structure that the running application depends on.

07 · Do Not Confuse

Migration

An ordered change that moves a database to a new version.

Backup

A recoverable copy of data, not an instruction for changing the schema.

Seed Data

Initial or sample records inserted for setup or development.

08 · Topic Glossary

ENGLISH TERM中文SIMPLE ENGLISH中文小白理解
Migration数据库迁移A controlled, versioned change to a database structure or data.有记录、有顺序地修改数据库结构或数据。
Schema数据库结构The shape and rules of stored database data.数据库中表、字段、关系和约束的整体结构。
Version版本A recorded state in the ordered history of changes.用来表示数据库已经进行到哪一步。
Migration File迁移文件A source-controlled file that describes one database change.保存在代码仓库里、描述一次数据库修改的文件。
Migration Runner迁移执行器A tool that finds and applies pending migrations.自动找出还没执行的迁移并按顺序运行它们的工具。
Rollback回滚Returning a database change to an earlier state.把数据库变化撤回到之前的状态。
Constraint约束A rule that protects the validity of stored data.用来防止错误数据进入数据库的一条规则。
Seed Data种子数据Initial or sample records inserted into a database.系统初始化或开发测试时预先放入的示例数据。

09 · What to Remember

A migration is a controlled, versioned change to a database schema or data structure.

Keep migrations ordered, reviewable, repeatable, and aligned with the application release that needs them.

↑