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 StructureAdd tables, columns, indexes, or constraints.
Version ChangesRecord which database state the system expects.
Apply SafelyRun an ordered change with review and deployment checks.
Move DataTransform 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 tableCreate storage for a new product capability.
Data QualityNew constraintRequire valid values or enforce a relationship.
PerformanceNew indexMake a frequent query faster without changing its meaning.
Release DeliveryEnvironment parityKeep 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);
- The migration file is reviewed and committed.
- A migration runner applies it once to each environment.
- Existing orders receive the safe default value.
- 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.