migrate-create
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMigrate Create
迁移创建
Generate a new database migration with sequential numbering and up/down SQL file pair.
生成一个带有顺序编号和up/down SQL文件对的新数据库迁移。
When to use
使用场景
When you need to create a new database migration for schema changes such as creating tables, adding columns, creating indexes, or modifying constraints.
当你需要为模式变更创建新的数据库迁移时,例如创建表、添加列、创建索引或修改约束。
Steps
步骤
- Determine next number -- use to scan the migrations directory for existing migration files and find the highest number, then increment by 1 (zero-pad to 3 digits)
Glob - Select template -- based on the , choose the appropriate SQL template:
<name>- Names starting with -> CREATE TABLE template
create_ - Names starting with -> ALTER TABLE ADD COLUMN template
add_ - Names starting with -> DROP with safety checks
drop_ - Names containing -> CREATE INDEX template
index - Other -> generic migration template with placeholder comments
- Names starting with
- Generate up migration -- write with the appropriate SQL using IF NOT EXISTS for idempotency
NNN_<name>.up.sql - Generate down migration -- write with the reverse operation using IF EXISTS
NNN_<name>.down.sql - Search patterns -- call to find similar past migrations for reference
mcp__claude-flow__agentdb_pattern-search - Store metadata -- call to record the migration in
mcp__claude-flow__agentdb_hierarchical-storenamespace with number, name, status (pending), and file pathsmigrations - Report -- display: migration number, file paths created, template used, any similar past migrations found
- 确定下一个编号——使用扫描迁移目录中的现有迁移文件,找到最大编号,然后加1(补零至3位)
Glob - 选择模板——根据选择合适的SQL模板:
<name>- 以开头的名称 -> CREATE TABLE模板
create_ - 以开头的名称 -> ALTER TABLE ADD COLUMN模板
add_ - 以开头的名称 -> 带有安全检查的DROP模板
drop_ - 包含的名称 -> CREATE INDEX模板
index - 其他 -> 带有占位符注释的通用迁移模板
- 以
- 生成up迁移文件——编写,使用IF NOT EXISTS确保幂等性
NNN_<name>.up.sql - 生成down迁移文件——编写,使用IF EXISTS执行反向操作
NNN_<name>.down.sql - 搜索模式——调用查找类似的过往迁移作为参考
mcp__claude-flow__agentdb_pattern-search - 存储元数据——调用在
mcp__claude-flow__agentdb_hierarchical-store命名空间中记录迁移信息,包括编号、名称、状态(pending)和文件路径migrations - 报告——显示:迁移编号、创建的文件路径、使用的模板、找到的任何类似过往迁移
CLI alternative
CLI替代方案
bash
npx @claude-flow/cli@latest memory store --namespace migrations --key "migration-NNN_NAME" --value '{"number": NNN, "name": "NAME", "status": "pending"}'bash
npx @claude-flow/cli@latest memory store --namespace migrations --key "migration-NNN_NAME" --value '{"number": NNN, "name": "NAME", "status": "pending"}'