Skip to content
Skills Library
Programming · Building & coding

db-migration

/db-migration

Creates goose SQL migrations and sqlc queries from the entity model, then regenerates the type-safe Go database code. Use when the user asks to "create a migration", "update the schema", "set up database tables", "write a goose migration", "add sqlc queries", or mentions schema migration, DB migration, database versioning, goose, or sqlc.

Licence
Apache-2.0
Last repository change
25.09.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 25.09.2026, without references to retired models or APIs.

Licence

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

What it does and when to use it

Creates goose SQL migrations and sqlc queries from the entity model, then regenerates the type-safe Go database code. Use when the user asks to "create a migration", "update the schema", "set up database tables", "write a goose migration", "add sqlc queries", or mentions schema migration, DB migration, database versioning, goose, or sqlc.

Triggers from the description

create a migrationupdate the schemaset up database tableswrite a goose migrationadd sqlc queries
Original author description

Creates goose SQL migrations and sqlc queries from the entity model, then regenerates the type-safe Go database code. Use when the user asks to "create a migration", "update the schema", "set up database tables", "write a goose migration", "add sqlc queries", or mentions schema migration, DB migration, database versioning, goose, or sqlc.

How it works

  1. Instructions
  2. DO NOT
  3. Nexa Rules Gate
  4. Worktree Gate
  5. Locations
  6. Example Migration
  7. Example Queries
  8. Entity Model → SQL Mapping
  9. Workflow
  10. Verification
Original SKILL.md headings · 176 lines, 874 words
SKILL.md preview
---
name: db-migration
description: >
  Creates goose SQL migrations and sqlc queries from the entity model, then regenerates the
  type-safe Go database code. Use when the user asks to "create a migration", "update the
  schema", "set up database tables", "write a goose migration", "add sqlc queries", or mentions
  schema migration, DB migration, database versioning, goose, or sqlc.
---

# DB Migration

## Instructions

Create or update the database schema as goose SQL migrations based on `docs/entity_model.md`,
and regenerate the sqlc Go code.

goose does not diff a schema — every migration is written by hand as SQL. That is intended:
the migration file *is* the reviewed change. Each file has an `-- +goose Up` and an
`-- +goose Down` section.

## DO NOT

- Edit a migration that has already been applied anywhere (merged to `main`, or run against dev) — add a new migration instead
- Drop or rename existing tables or columns without explicit user confirmation (a `DROP` in the `-- +goose Down` section of a new migration is expected and fine)
- Edit anything under `internal/db/` — it is generated by `sqlc generate`
- Skip relations defined in the entity model — every relation becomes a foreign key
- Use `serial` / `bigserial` IDs unless the entity model explicitly requires them (use `uuid` with `DEFAULT gen_random_uuid()`)

## Nexa Rules Gate

Read and follow `${CLAUDE_PLUGIN_ROOT}/shared/readiness/NEXA_RULES_GATE.md`.

## Worktree Gate

Read and follow `${CLAUDE_PLUGIN_ROOT}/shared/readiness/WORKTREE_GATE.md`.

## Locations

```
db/migrations/NNNNN_<name>.sql   # goose migrations (schema source for sqlc)
db/migrations/embed.go           # embeds the migrations, exposes Up(ctx, dsn)
db/queries/<entity>.sql          # sqlc queries
sqlc.yaml
internal/db/                     # generated — committed, never edited
```

## Example Migration

```sql
-- +goose Up
CREATE TABLE room_type (
    id          uuid          PRIMARY KEY DEFAULT gen_random_uuid(),
    name        varchar(50)   NOT NULL UNIQUE,
    description varchar(500),
    capacity    integer       NOT NULL CHECK (capacity > 0),
    price       numeric(10,2) NOT NULL
);

CREATE TABLE room (
    id           uuid        PRIMARY KEY DEFAULT gen_random_uuid(),
    number       varchar(10) NOT NULL UNIQUE,
    room_type_id uuid        NOT NULL REFERENCES room_type (id)
);

CREATE INDEX room_room_type_id_idx ON room (room_type_id);

-- +goose Down
DROP TABLE room;
DROP TABLE room_type;
```

## Example Queries

```sql
-- name: GetRoomType :one
SELECT * FROM room_type WHERE id = $1;

-- name: ListRoomTypes :many
SELECT * FROM room_type ORDER BY name;
```

## Entity Model → SQL Mapping

| Entity model | PostgreSQL |
|---|---|
| ID | `uuid PRIMARY KEY DEFAULT gen_random_uuid()` |
| String with max length | `varchar(N)` |
| Text without limit | `text` |
| Integer / Long | `integer` / `bigint` |
| Decimal / money | `numeric(P,S)` — never `float` for money |
| Boolean | `boolean NOT NULL DEFAULT false` (or the model's default) |
| Date / DateTime | `date` / `timestamptz` |
| Enum | `text` + `CHECK (col IN (...))` |
| Required | `NOT NULL` |
| Unique | `UNIQUE` |
| Min / max value | `CHECK (...)` |
| Many-to-one | `<entity>_id uuid NOT NULL REFERENCES <entity> (id)` + index |
| Many-to-many | join table with composite primary key of both foreign keys |

Table and column names are `snake_case`, singular table names.

## Workflow

1. Read `docs/entity_model.md`
2. Read the existing migrations in `db/migrations/` (if any) to know the current schema
3. Bootstrap once, if missing:
   - `sqlc.yaml`:
     ```yaml
     version: "2"
     sql:
       - engine: "postgresql"
         schema: "db/migrations"
         queries: "db/queries"
         gen:
           go:
             package: "db"
             out: "internal/db"
             sql_package: "pgx/v5"
             emit_interface: true
     ```
   - `db/migrations/embed.go`:
     ```go
     package migrations

     import (
     	"context"
     	"database/sql"
     	"embed"

     	_ "github.com/jackc/pgx/v5/stdlib"
     	"github.com/pressly/goose/v3"
     )

     //go:embed *.sql
     var FS embed.FS

     // Up applies every pending migration to the database at dsn.
     func Up(ctx context.Context, dsn string) error {
     	db, err := sql.Open("pgx", dsn)
     	if err != nil {
     		return err
     	}
     	defer db.Close()
     	p, err := goose.NewProvider(goose.DialectPostgres, db, FS)
     	if err != nil {
     		return err
     	}
     	_, err = p.Up(ctx)
     	return err
     }
     ```
   - `db/migrations/migrations_integration_test.go` — the round-trip check (build tag
     `integration`): start a testcontainers-go Postgres container, run `Up`, then
     `goose.NewProvider(...).DownTo(ctx, 0)`, then `Up` again; fail on any error. This proves
     every `Down` section reverses its `Up`.
   - Tools: `go get -tool github.com/pressly/goose/v3/cmd/goose`; verify `sqlc version` (install
     the binary per the sqlc docs if missing). Use context7 to confirm goose and sqlc
     configuration for the installed versions.
4. Create the migration file: `go tool goose -dir db/migrations create <descriptive_name> sql`
5. Write the `Up` section from the entity model (see the mapping table) and a `Down` section that
   reverses it exactly, in reverse dependency order
6. Ensure relations match the entity model (foreign keys, join tables, `ON DELETE` behaviour only
   when the model states it)
7. For each new table, add `db/queries/<entity>.sql` with a get-by-id and a list query if the file
   does not exist. Use-case-specific queries are added later by `/implement`
8. Run `sqlc generate`
9. Validate the migration:
    - `go test -tags=integration ./db/migrations/` passes — the migrations apply to a fresh
      container and survive a full down/up round trip (Docker must be running)
    - `go build ./...` succeeds against the regenerated `internal/db/`
    - Every entity in the entity model has a table; every attribute has a column with the mapped
      type and constraints; every relation has a foreign key
    - Read the migration SQL once more for a destructive statement in `Up` — if there is one,
      confirm with the user

## Verification

The skill is complete when:

- `go test -tags=integration ./db/migrations/` exits 0
- `sqlc generate` exits 0 and `go build ./...` exits 0
- `internal/db/` changes are staged with the migration (generated code is committed)
- No previously applied migration file was modified (`git diff origin/main -- db/migrations/` shows only added files)

Versions

RepositoryScoreLicence
This page · nexadevapp/nexa-claude-skills-marketplace100Apache-2.0
byerlikaya/claude-starter-kit100MIT
andreibesleaga/gabbe100CC-BY-4.0
globalmpc/backendskills100MIT
omexit/claude-skills-pack100MIT
globalmpc/backendskills95MIT
chatquill/claude-code-websites90MIT
nguyengiavu/ngvu-factory90MIT
a-pavithraa/springboot-skills-marketplace86MIT

Database snapshot: 13.11.2026 · package version cce749a10386 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 1 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100prisma-migration
    Creates Prisma schema models and generates database migrations from the entity model. Use when the user asks to "create a migration", "update the schema", "set up database tables", "write a Prisma migration", or mentions schema migration, DB migration, database versioning, or Prisma schema changes.
  • 100sqlc
    Add SQL queries, run code generation, and configure type overrides for the hive SQLite data layer. Use when writing new queries, adding tables, or mapping domain types to generated code.
  • 100postgresql
    Use when working with the Speakeasy PostgreSQL database: schema design, server/database/schema.sql, migrations, atlas.sum, sqlc queries, indexes, foreign keys, CHECK constraints, or reviewer suggestions to add constraints
  • 100set-up-database
    Use when a backend needs Postgres, or its schema changes by hand or by `db push` — sets up local Postgres via compose, the ORM or sqlc, pooling, service-layer transactions, versioned reviewed migrations, seed data, and a migration-safety gate.
  • 100go-database
    Database patterns for Go services: database/sql, connection management, transactions, migrations, query builders, and ORM usage (sqlc, GORM, ent). Use when: "database access", "SQL query", "connection pool", "transactions", "database migration", "sqlc", "GORM", "ent", "prepared…
  • 95goose
    Write, read, review, debug, and port code in Goose, the memory-safe systems programming language by Wouter van Oortmerssen (source files end in .goose; the compiler is `goose`). Use this whenever a task involves Goose source, a .goose file, the Goose compiler or standard…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.