db-migration
Database Migration Workflow
Workflow for database schema and migration changes.
Prerequisites
- Use
git-workflowSkill for branch, commit, and PR workflow. - Refer to
.claude/rules/hcl.mdfor HCL schema rules (SSOT). - Refer to
.claude/rules/sql.mdfor SQL query rules (SSOT).
Applicable Files
| Path | Description |
|---|---|
tools/atlas/schemas/{db_dialect}/*.hcl |
HCL schema definitions (source of truth) |
tools/sqlc/queries/{db_dialect}/*.sql |
SQLC query definitions |
Workflow
1. Modify Schema (HCL)
Edit HCL files in tools/atlas/schemas/{db_dialect}/.
Dialect directories:
tools/atlas/schemas/postgres/*.hcltools/atlas/schemas/mysql/*.hcl
2. Verify HCL (from rules/hcl.md)
make atlas-fmt && make atlas-lint
3. Regenerate All Artifacts
Run all three targets after modifying HCL schemas:
# Regenerate migrations, extract SQLC schemas, and generate Go code for PostgreSQL
make regenerate-all-from-atlas
# Regenerate for MySQL
make regenerate-all-from-atlas-mysql
# Convert PostgreSQL schemas to SQLite and generate Go code for SQLite
make regenerate-all-from-atlas-sqlite
Each target handles: Atlas migrations → Docker DB reset → SQLC schema extraction → SQLC code generation.
4. Verify Migration Files
After running the regenerate targets, confirm each DB dialect has exactly one migration SQL file:
tools/atlas/migrations/postgres/{db-name}/*.sql← one file, updatedtools/atlas/migrations/mysql/{db-name}/*.sql← one file, updated
DB names: keygen, sign, watch
5. Verify Go Code
make check-build && make go-test
Self-Review Checklist
- HCL format/lint passes
-
make regenerate-all-from-atlassucceeds (postgres) -
make regenerate-all-from-atlas-mysqlsucceeds (mysql) -
make regenerate-all-from-atlas-sqlitesucceeds (sqlite) - Each
tools/atlas/migrations/{postgres,mysql}/{db-name}/has exactly one.sqlfile and it is updated - SQLC generates correctly
- Go build passes
Related
.claude/rules/hcl.md- HCL rules (SSOT).claude/rules/sql.md- SQL rules (SSOT)go-development- Go verification after SQLC generationgit-workflow- Branch, commit, PR workflow
More from hiromaily/go-crypto-wallet
makefile-update
Makefile development workflow. Use when modifying Makefile or files in make/ directory.
33docs-update
Documentation update workflow. Use when modifying files in docs/ directory or any markdown files (*.md).
33btc-terminology
Critical Bitcoin terminology rules to prevent confusion between bech32m (encoding) and taproot (address type). Use when working on BTC-related code, config files, or shell scripts.
33shell-scripts
Shell script development workflow. Use when modifying files in scripts/ directory or any *.sh files.
33openspec-propose
Propose a new change with all artifacts generated in one step. Use when the user wants to quickly describe what they want to build and get a complete proposal with design, specs, and tasks ready for implementation.
21mockery
>
14