dbmate 数据库迁移管理
dbmate
使用 dbmate 管理数据库迁移。
- License 许可
- MIT
- 最近更新
- 2026-09-30
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- dbmate
- description
- Managing database migrations with dbmate
03 SKILL.md 正文
dbmate Skill
This skill provides comprehensive instructions for managing database migrations in this project using dbmate.
Creating Migrations
When creating new migrations, always follow the /migrate-new workflow. The primary tool for creating a migration is:
dbmate --migrations-dir db/migrations/<engine> new "migration_name"
Replace <engine> with sqlite, postgres, or mysql.
Writing Migrations
Migrations are stored in db/migrations/<engine>/ as .sql files. They follow a specific format:
Structure
Each migration file MUST have two sections:
-- migrate:up
-- SQL statements to apply the change
-- migrate:down
-- SQL statements to reverse the change
Transaction Handling
[!IMPORTANT] DO NOT wrap your SQL in
BEGIN/COMMITblocks.dbmateautomatically wraps each migration in a transaction. Adding manual transaction blocks will cause errors and may lead to inconsistent database states.
SQL Guidelines
- Idempotency: Use
IF NOT EXISTSor similar where possible to make migrations safer (e.g.,CREATE TABLE IF NOT EXISTS ...). - Schema Files: NEVER edit files in
db/schema/manually. They are auto-generated. - Engine-Specifics: Ensure you tailor the SQL for the specific database engine.
- PostgreSQL: Use appropriate types (e.g.,
TEXT,JSONB). - MySQL: Use compatible types (e.g.,
LONGTEXTfor JSON-like data). - SQLite: Be mindful of limited
ALTER TABLEsupport.
- PostgreSQL: Use appropriate types (e.g.,
Applying Migrations
For development, use ./dev-scripts/migrate-all.py. This script:
- Applies migrations for all engines (PostgreSQL, MySQL, SQLite).
- Updates the schema files in
db/schema/.
04 同仓库更多 Skills
OpenSpec 变更验证
openspec-verify-change
验证实现是否与变更工件一致。当用户想要在归档前验证实现是否完整、正确且连贯时使用。
OpenSpec 规格同步
openspec-sync-specs
将变更中的增量规格(delta spec)同步到主规格。当用户想要用增量规格中的变更更新主规格,而不归档该变更时使用。
OpenSpec 变更提案
openspec-propose
一步生成所有工件,提出新的变更。当用户想要快速描述要构建的内容,并获得包含设计、规格和任务的完整提案以供实施时使用。
启动 OpenSpec 新变更
openspec-new-change
使用实验性工件工作流启动新的 OpenSpec 变更。当用户想要以结构化的分步方式创建新功能、修复或修改时使用。
OpenSpec 工件快速创建
openspec-ff-change
快速推进 OpenSpec 工件创建。当用户想要快速创建实现所需的全部工件,而无需逐个操作时使用。
OpenSpec 需求探索
openspec-explore
进入探索模式——作为思考伙伴,帮助探索想法、排查问题并澄清需求。当用户想在变更之前或期间深入思考某事时使用。