一键导入
db-migrate
Use when creating or modifying database schema in Go projects using golang-migrate with PostgreSQL
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when creating or modifying database schema in Go projects using golang-migrate with PostgreSQL
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when the user wants to free disk space, investigate disk usage, clean caches, remove unused artifacts, or when disk capacity is high. Also use when asked to "clean up", "free space", "disk full", or "what's using disk space". Always uses AskUserQuestion for every deletion decision.
Use at the start of every conversation and for every user message — orchestrates the full engineering skills suite by understanding intent, clarifying requirements interactively, and invoking the right skills
Use when refactoring Go code, cleaning up legacy codebases, optimizing performance, or enforcing clean architecture boundaries in a Go/Fiber backend
Use when refactoring Python code, cleaning up legacy codebases, optimizing performance, enforcing type safety, or improving clean architecture in a FastAPI backend
Use when refactoring React components, cleaning up legacy frontends, optimizing performance, improving component architecture, or reducing bundle size
Use when reviewing changed code before committing or after completing a feature — checks performance, architecture, type safety, and code quality against project standards
| name | db-migrate |
| description | Use when creating or modifying database schema in Go projects using golang-migrate with PostgreSQL |
Safe, reversible PostgreSQL schema changes using golang-migrate. Every migration must be idempotent and have a working rollback.
Core principle: Every up.sql must have a working down.sql. Verify with up → down → up cycle.
migrations/
000001_create_users_table.up.sql
000001_create_users_table.down.sql
000002_add_user_email_index.up.sql
000002_add_user_email_index.down.sql
Sequential numbering. Descriptive names. Always pairs.
MIGRATE=migrate -path migrations -database "$(DATABASE_URL)"
migrate-up:
$(MIGRATE) up
migrate-down:
$(MIGRATE) down 1
migrate-create:
migrate create -ext sql -dir migrations -seq $(name)
migrate-force:
$(MIGRATE) force $(version)
-- Tables: always IF NOT EXISTS
CREATE TABLE IF NOT EXISTS users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- Indexes: CONCURRENTLY to avoid locks
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_users_email ON users (email);
-- Columns: nullable first for zero-downtime
ALTER TABLE users ADD COLUMN IF NOT EXISTS phone TEXT;
-- Later migration: backfill, then NOT NULL
| Operation | Safe Approach |
|---|---|
| Add column | Add as nullable → backfill → add NOT NULL constraint |
| Drop column | Stop reading → deploy → drop in next migration |
| Rename column | Add new → copy data → update code → drop old |
| Add NOT NULL | Add with DEFAULT first |
| Add index | Use CONCURRENTLY |
| Drop table | Remove all references first |
| Go Type | Postgres Type |
|---|---|
uuid.UUID | UUID |
time.Time | TIMESTAMPTZ |
string | TEXT |
int64 | BIGINT |
float64 | DOUBLE PRECISION |
map/struct | JSONB |
bool | BOOLEAN |
-- up.sql
CREATE TYPE user_role AS ENUM ('admin', 'member', 'viewer');
ALTER TABLE users ADD COLUMN role user_role NOT NULL DEFAULT 'member';
-- down.sql
ALTER TABLE users DROP COLUMN IF EXISTS role;
DROP TYPE IF EXISTS user_role;
-- Adding values to existing enum (cannot be in transaction)
ALTER TYPE user_role ADD VALUE IF NOT EXISTS 'moderator';
Always run the idempotency check:
make migrate-up && make migrate-down && make migrate-up
down.sql — always write rollbackVARCHAR(n) — prefer TEXT in PostgresTIMESTAMP without timezone — always use TIMESTAMPTZclaude-md)