迁移
一句话解释
迁移是 script 那个修改数据库 Schema — 创建表, 添加列, etc. — tracked in version control.
用大白话说
A migration is a script that changes the database schema. Instead of manually editing tables in production, you write migration scripts that are version-controlled and applied in order.
A typical migration system has "上" and "下" scripts:
- Up: applies the change (e.g., adds a column).
- Down: reverses the change (e.g., drops the column).
Migrations are tracked in a special table so the system knows which ones have been applied. This lets you:
- Reproduce the database schema in any environment.
- Roll back changes if something goes wrong.
- Collaborate on schema changes through version control.
Tools like Flyway, Liquibase, Alembic, and Prisma Migrate manage migrations for various languages and frameworks.
示例
sql
-- Migration 003: add phone column to users
-- Up
ALTER TABLE users ADD COLUMN phone TEXT;
-- Down
ALTER TABLE users DROP COLUMN phone; 迁移添加 phone 列. 下迁移 reverses 它通过 dropping 列.
相关术语
相关资源
相关课程
- 迁移
学习如何 manage Schema 更改使用迁移.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。