db-sqlc-schema
Write or modify SQL migration files (goose) and sqlc query files, then regenerate Go code. Use for database model, relation, index, enum changes, or schema-to-domain-layer sync.
- License 许可
- MIT
- 最近更新
- 2026-09-06
- Stars
- ★ 3
- Forks
- 0
01 前言 Front Matter
- name
- db-sqlc-schema
- description
- Write or modify SQL migration files (goose) and sqlc query files, then regenerate Go code. Use for database model, relation, index, enum changes, or schema-to-domain-layer sync.
02 资源文件 3
- 参考文档agents/openai.yaml317 B
- 参考文档references/context.md1.6 KB
- 参考文档templates/checklist.md976 B
03 SKILL.md 正文
Skill: DB sqlc Schema
Context (Required)
- Folder scope + code samples:
references/context.md - Execution checklist:
templates/checklist.md
Apply schema changes minimally and safely. Goose manages migrations, sqlc generates type-safe Go from SQL queries.
Naming Conventions
Tables
| Category | Table Prefix |
|---|---|
| Master / reference data | master_ |
| Transaction / business data | business_ |
| Membership data | member_ |
| User / auth data | users, auth_* |
| System config data | configurations |
Columns
- snake_case always
- Boolean fields — prefix
is_orhas_ - Enum-like fields — use
VARCHAR+ Go const, not PostgreSQL ENUM (prefer consistency)
Required Standard Columns
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
created_at TIMESTAMP(6) NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP(6) NOT NULL DEFAULT NOW()
Workflow
- Write goose migration SQL in
apps/api/db/migrations/ - Write or update sqlc query in
apps/api/db/queries/ - Run:
sqlc generatefromapps/api/ - Update domain entity + repository interface if schema changes affect them
- Update
pgx_{domain}_repository.goto use new generated query
Goose Migration Format
-- +goose Up
CREATE TABLE master_categories (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(100) NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT TRUE,
created_at TIMESTAMP(6) NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP(6) NOT NULL DEFAULT NOW()
);
-- +goose Down
DROP TABLE IF EXISTS master_categories;
sqlc Query Format
-- name: FindCategoryByID :one
SELECT id, name, is_active, created_at, updated_at
FROM master_categories
WHERE id = $1;
-- name: CreateCategory :one
INSERT INTO master_categories (name, is_active)
VALUES ($1, $2)
RETURNING id, name, is_active, created_at, updated_at;
-- name: ListCategories :many
SELECT id, name, is_active, created_at, updated_at
FROM master_categories
ORDER BY created_at DESC;
Prohibitions
- NEVER edit files in
internal/infrastructure/db/— they are sqlc-generated. Always regenerate. - NEVER rename a table or column without a clear migration that handles the rename.
- NEVER drop an existing column without documenting the migration impact.
- NEVER use PostgreSQL ENUM type — use VARCHAR with Go typed constants instead.
- NEVER add a migration without a corresponding
-- +goose Downblock.
Pre-Completion Checklist
- [ ] Migration file created with sequential filename (
000XX_description.sql) - [ ]
-- +goose Upand-- +goose Downblocks present - [ ] Standard columns present: id, created_at, updated_at
- [ ] sqlc query file created/updated
- [ ]
sqlc generaterun — no errors - [ ] Domain entity updated if shape changed
- [ ] Repository interface updated if new queries added
- [ ] pgx repository implementation updated
- [ ]
go build ./...passes - [ ] All files end with a newline (EOF)
04 同仓库更多 Skills
web-slicing
Convert screenshot/Figma designs into pixel-perfect frontend UI with reusable components. Use when the task focuses on visual and layout implementation.
web-seo-geo-friendly
Optimize public Next.js App Router pages for SEO and GEO (Generative Engine Optimization). Use when the user explicitly requests SEO/GEO optimization on public pages.
web-code-review
Review frontend code with a firm senior-lead standard, focusing on bugs, regressions, architecture risks, and test gaps in apps/web and the shared contracts the frontend depends on.
web-bugfix
Fix frontend bugs with minimum-touch changes, keep other surfaces stable, and sync schema, types, hooks, constants, tests, and related docs when impacted.
web-api-integrated
Integrate API endpoints into the frontend with Zod schemas, response types, constants, and react-query hooks. Use when implementing endpoints from an API contract, Postman, or Swagger.
skill-creator
Create a new skill from scratch with full structure — SKILL.md, references, templates, openai.yaml, Claude/OpenCode wrappers, and registration in manifest + AGENTS.md + CLAUDE.md.