---
name: "golang-migrate-cli-database-tool"
description: "Version-control SQL schema migrations with up/down scripts using golang-migrate."
metadata:
  author: "golang-migrate"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "run golang-migrate up"
  - "create migration golang-migrate"
  - "fix dirty database state migrate"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# golang-migrate CLI & Programmatic Database Migrations

Applies migrations using golang-migrate: writing versioned SQL scripts (000001_init.up.sql, 000001_init.down.sql), running migrations via CLI, integrating programmatically in Go main(), and resolving dirty state.

## When to Invoke
Invoke this skill whenever you need to:
- run golang-migrate up
- create migration golang-migrate
- fix dirty database state migrate

## Execution SOP & Rules
1. Create migration pair: migrate create -ext sql -dir migrations -seq init_schema.
2. Write idempotent DDL in *.up.sql and reverse cleanup in *.down.sql.
3. Apply migrations: migrate -database 'postgres://...' -path migrations up.
4. Fix dirty state: migrate -database '...' -path migrations force <version>.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
