Write, register, review and apply a SeaORM 2.0 migration (sea-orm-migration crate) in a Rust axum project on this convention (migration/ workspace crate, entities in src/domains/{d}/entity.rs, migration CLI reading DB_*). SeaORM does not diff entities against the database, so the migration body is hand-written from the entity. Generates the file with sea-orm-cli, registers it in migration/src/lib.rs, writes up and a real down, gates destructive Postgres schema changes (drop_column, drop_table, rename, modify_column, raw SQL) on scratch-database evidence and user approval, then round-trips it on the dev DB. Use when an axum/SeaORM entity was added or changed, or a migration must be rolled back, e.g. "coupon 엔티티에 컬럼 추가했어, 마이그레이션 만들어줘", "generate the SeaORM migration for the new entity", "마이그레이션 롤백해줘". Do NOT use for TypeORM projects (nestjs-migration), Alembic projects (fastapi-migration), scaffolding a new axum domain and its entity (axum-domain-module), or bootstrapping the axum project (axum-bootstrap).
Ships in backend. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
SeaORM does not diff entities against the database. There is no autogenerate step:
sea-orm-cli migrate generate writes an empty file whose up and down are todo!(), and every
statement in it is written by hand from the entity in src/domains/<d>/entity.rs. So this skill
does five things: generate the file, make sure it is registered, write up and a real down from
the entity, gate destructive operations before they reach the dev database, and prove the result
with a round trip and the test suite.
This skill changes a database. Nothing destructive is applied to the dev database without the user's explicit approval in this conversation.
{
"name": "create_coupon", // snake_case verb_subject; the generator prepends m<YYYYMMDD_HHMMSS>_
"apiRoot": "." // the Cargo workspace holding migration/: "." standalone, "apps/api" in the monorepo
}
{
"migrationFile": "migration/src/m20261130_043355_create_coupon.rs", // relative to apiRoot
"verdict": "safe" | "needs-review",
"destructiveOps": [], // e.g. ["ALTER TABLE \"coupon\" DROP COLUMN \"memo\""]; non-empty means needs-review
"applied": true // false whenever the dev database was not migrated: needs-review, or the caller owns the apply
}
Run every command from the api root. In the monorepo, .env and docker-compose.yml sit at the
repo root; docker compose finds the file from apps/api by walking up.
The api root has a Cargo.toml with [workspace] members = [".", "migration"],
migration/src/lib.rs and migration/src/main.rs. If migration/ is missing, the project was not
bootstrapped with this convention: stop and point at axum-bootstrap.
Read the entity the migration is for. It is the source of truth for columns and types. Its doc
comment says where a unique constraint lives (plain UNIQUE, or a partial unique index when the
table is soft-deletable). A service that maps SqlErr::UniqueConstraintViolation to a domain error
confirms which column is unique. If the entity does not yet reflect the requested change, edit
entity.rs first (fields only). Code elsewhere that still uses a removed or renamed field is not
this skill's to redesign: name it in the report. Deleting or renaming the field's mentions so the
crate compiles (DTO fields, repository and service arguments, test bodies) is allowed and
expected, since step 8 needs cargo clippy and cargo test green; changing behaviour is not. List
every API field that disappears, because that is a contract change for the API's consumers.
cargo run -p migration -- status
docker compose up -d db, or any Postgres .env points at). If it
is not, stop and report. missing environment variables: DB_HOST, ... means .env is absent.Migration file of version '...' is missing, this migration has been applied but its file is missing means the database holds another project's schema (often a reused compose volume). Stop
and report.Applied. A Pending one that is not yours would be applied by
your up too, ungated: stop and report blocked: pending migrations <names>.sea-orm-cli migrate generate <name>
Do not run cargo run -p migration -- generate <name> from the api root: it writes the file into
./src/ of the api crate (G2). cd migration && cargo run -- generate <name> is the only
alternative.
Then check registration, every time, because the generator prints Adding migration ... to ./migration/src/lib.rs even when it did not add it:
N=$(basename "$(ls migration/src/m*_<name>.rs)" .rs)
grep -c "mod $N;" migration/src/lib.rs # must print 1
grep -c "Box::new($N::Migration)" migration/src/lib.rs # must print 1
Later steps use $N again. Shell state does not carry between tool calls, so set it again in each
new shell.
The very first migration, into an empty vec![], gets only mod ...; appended at the end of the
file and no Box::new entry (G1). Add Box::new(<N>::Migration) to the vec! in migrations()
by hand and move the mod line up next to the others. From the second migration on, the generator
registers both.
up and down from the entityReplace both todo!() bodies and rename _manager to manager. Use the schema::* helpers the
file already imports. Plain helpers are NOT NULL, _null helpers are nullable, _uniq add
UNIQUE:
| Entity field | Column helper |
|---|---|
#[sea_orm(primary_key)] id: i64 | big_pk_auto("id") (Postgres bigint generated by default as identity) |
String / Option<String> | string / string_null (text / text_null for column_type = "Text") |
i16 / i32 / i64 | small_integer / integer / big_integer (append _null for Option) |
bool | boolean |
f64 | double |
created_at, updated_at: DateTimeUtc | timestamp_with_time_zone_default_now(...) |
Option<DateTimeUtc> (e.g. deleted_at) | timestamp_with_time_zone_null(...) |
other DateTimeUtc | timestamp_with_time_zone(...) |
Never use table_auto(), timestamps() or timestamp(...): they create timestamp without time
zone, which does not match DateTimeUtc (G4).
Unique columns:
string_uniq("code").deleted_at present): a plain column plus a partial unique index, so a deleted
row does not block a new one:manager
.create_index(
Index::create()
.name("uq_user_email_active")
.table("user")
.col("email")
.unique()
.and_where(Expr::col("deleted_at").is_null())
.to_owned(),
)
.await
Changing an existing table uses Table::alter().table("coupon") with .add_column(...),
.drop_column(...), .rename_column("old", "new") or .modify_column(...). A rename is always
rename_column, never drop + add, which loses the column's data.
down undoes up exactly: drop_table for create_table (its indexes go with it), drop_column
for add_column, drop_index for a standalone create_index, the reverse rename_column for a
rename. A down that drops a column up removed can only restore the column, not its values: say
so in a comment in down and in the report. If the dropped column was NOT NULL without a
default, restore it in two statements so the schema matches exactly and down still runs on a
table with rows: add_column with a placeholder .default(...) (0, '', false), then drop that
default with manager.get_connection().execute_unprepared(r#"ALTER TABLE "<table>" ALTER COLUMN "<col>" DROP DEFAULT"#). modify_column cannot do the second step: it re-emits only TYPE and
SET NOT NULL and leaves the default in place (measured on postgres:16, 2026-11-30).
execute_unprepared in down does not trip the step 5 gate, which reads up only.
Then:
grep -n 'todo!' migration/src/$N.rs # must print nothing
cargo fmt
Grep the up body only. Every create migration's down contains drop_table, so grepping the
whole file flags every migration:
sed -n '/async fn up/,/async fn down/{=;p;}' migration/src/$N.rs | sed 'N;s/\n/: /' \
| grep -E 'drop_table|drop_column|drop_index|drop_foreign_key|modify_column|rename_column|rename_table|truncate_table|execute_unprepared|not_null\(\)'
sed -n '/async fn up/,/async fn down/{=;p;}' migration/src/$N.rs | sed 'N;s/\n/: /' \
| grep -E 'add_column(_if_not_exists)?\(' | grep -vE '_null\(|default'
The second grep finds a NOT NULL column without a default added to an existing table. Postgres
rejects it once the table has rows, so it passes on an empty dev database and fails in production.
Prefer a _null column or a .default(...). If the column must be NOT NULL without a default,
it is needs-review.
Statement in up | Meaning | Verdict |
|---|---|---|
create_table, create_index, nullable or defaulted add_column | additive | safe |
drop_table, drop_column, truncate_table | data loss | needs-review |
modify_column, not_null(), NOT NULL add_column without default | may fail or truncate on real rows | needs-review |
rename_column, rename_table | breaks code still running against the old name during a deploy | needs-review |
drop_index, drop_foreign_key | removes a guarantee | needs-review |
execute_unprepared | raw SQL the grep cannot read | needs-review |
Any hit means verdict: "needs-review". No hit means verdict: "safe": go to step 7.
Show the real SQL and what down does to data, on a throwaway database <DB_NAME>_review.
Run the block in one shell: it needs .env loaded, $N from step 3, and K, the
migrations before yours. In the monorepo, source ../../.env instead.
set -a; . ./.env; set +a
K=$(( $(grep -c 'Box::new(' migration/src/lib.rs) - 1 ))
docker compose exec -T db psql -U "$DB_USER" -d postgres -c "CREATE DATABASE ${DB_NAME}_review"
DB_NAME=${DB_NAME}_review cargo run -p migration -- up -n $K
# seed one realistic row with a value in every column the up touches; the table and columns are
# this migration's, e.g. INSERT INTO coupon (code, discount_percent) VALUES ('KEEP', 30)
docker compose exec -T db psql -U "$DB_USER" -d ${DB_NAME}_review \
-c "INSERT INTO <table> (<columns>) VALUES (<values>)"
DB_NAME=${DB_NAME}_review cargo run -p migration -- -v up 2>&1 \
| sed -n "/Applying migration '$N'/,\$p" | grep -o 'db.statement=.*rows_affected'
docker compose exec -T db psql -U "$DB_USER" -d ${DB_NAME}_review -c "SELECT * FROM coupon"
DB_NAME=${DB_NAME}_review cargo run -p migration -- down
docker compose exec -T db psql -U "$DB_USER" -d ${DB_NAME}_review -c "SELECT * FROM coupon"
docker compose exec -T db psql -U "$DB_USER" -d postgres -c "DROP DATABASE ${DB_NAME}_review"
Without Docker, run the same psql commands with -h "$DB_HOST" -p "$DB_PORT".
A table whose name is a Postgres reserved word (user, order, group) must be double-quoted in
every hand-written SQL line: SELECT * FROM "user", \d "user". The SeaORM schema builder in
up/down quotes for you; raw psql -c and execute_unprepared do not. Unquoted, INSERT INTO user is a syntax error and, worse,
SELECT * FROM user succeeds and returns the current role name instead of the table (measured
on postgres:16, 2026-11-30).
Always drop the review database, also when a step failed.
Put each statement your migration printed into destructiveOps, unescaped, e.g.
ALTER TABLE "coupon" DROP COLUMN "memo". Skip the seaql_migrations insert and the empty
COMMIT line: that is the CLI's bookkeeping. Compare the seeded row before up and after down. If
the values are gone (memo came back empty), down restores the schema but not the data: say so
plainly.
Then run step 8's static checks and cargo test. They never touch the dev database, and
cargo test catches an entity that disagrees with the migrated schema (step 8).
safe: apply to the dev database and run the round trip (step 8).cargo test migrates every test schema itself, so it proves the
migration against the entity without the dev DB), and report applied: false next to the
contract so the caller knows the apply is still its job.needs-review, interactive: show the user every entry of destructiveOps with the evidence from
step 6 and ask whether it is intended. Then stop and wait. Apply to the dev database only after
an explicit yes in the conversation.
up (a rename as
rename_column), then start again at step 3.needs-review, non-interactive or pre-approved run: never apply it. "Pre-approved" covers
safe migrations only, and a request that names the destructive change ("drop this column and
apply it") is not approval either: the approval is of the step 6 evidence, which nobody has seen
yet. Count what the dev database would lose (rows of a dropped table, non-null values of a dropped
column) and put that number in the report with the contract (applied: false) and the
evidence, then stop.Dev database round trip, for safe or approved migrations only, and never when the caller owns
applying migrations (step 7):
cargo run -p migration -- up
cargo run -p migration -- status # yours: Applied
cargo run -p migration -- down # rolls back exactly one: yours
cargo run -p migration -- status # yours: Pending
cargo run -p migration -- up
Always:
cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo test
Clippy covers the migration crate only because the root Cargo.toml has
default-members = [".", "migration"] (G5). If that line is missing, run
cargo clippy --workspace --all-targets -- -D warnings and report the missing line.
cargo test needs the database up. Each test migrates its own schema in <DB_NAME>_test from
scratch, so it is the check that the entity and the migrated schema agree. An entity that still
declares a column the migration dropped builds fine and fails here:
code: "42703", message: "column \"memo\" does not exist". Fix the entity or the migration, never
the test.
cargo run -p migration -- status. The last Applied entries are what down reverts.down body of each migration to be reverted and run the step 5 grep on it
(awk '/async fn down/,0' ...). For every table it drops, count its rows; for every
column, count the rows where it is not null (SELECT count(*) FROM coupon WHERE memo IS NOT NULL). Rows that would be lost need the user's explicit yes, even though
they asked for the rollback. In a non-interactive run, report and stop.cargo run -p migration -- down reverts one; down -n 2 reverts two.cargo run -p migration -- status, then cargo test.The file stays registered, so the next up applies it again. To remove the change for good,
discard it.
If it was applied, cargo run -p migration -- down first: once the file is deleted the CLI refuses
to run against a database that still records it. Then delete migration/src/<N>.rs, remove its
mod line and Box::new entry from migration/src/lib.rs, revert the entity edit, and run
cargo test.
Return the output contract, then:
up runs (from -v up when step 6 ran), and what down does to data;cargo run -p migration -- up | down [-n N] | status. That CLI
reads DB_* from .env. sea-orm-cli migrate up reads DATABASE_URL, which this project does
not set, so it would hit the wrong database or none.docker compose run --rm app /app/migration up.fresh, refresh or reset on a database with data without the user's explicit
approval: they drop every table.What SKILL.md sets; muted values are Claude Code's defaults
/backend:axum-migrationfrom backend
npx claudepluginhub siu9068/ggyul-skills --plugin backend11 skills in this plugin
/api-creator-bootstrapGenerates a backend repo's `api-creator` + `test-checker` skill pair: set up, port, or bootstrap the API + test skills here. Generate a project-tailored TDD skill PAIR — `api-creator` (scaffold new APIs) and `test-checker` (audit & fill existing unit tests) — for a backend project: extract the proven gated, test-first methodology and fill in THIS project's own conventions (layers, base classes, auth, DTO/serialization, folder layout, test framework, verify commands). Both skills share one discovered recipe so they stay consistent. Use whenever the user wants to "set up api-creator here", "port the api-creator/test-checker skills to this project", "bootstrap the API + test skills for this repo", or bring one project's API + test conventions into another as reusable skills. Do NOT use this to actually build an API or audit tests in the current project (that is the generated skills' job), nor to edit an existing skill (use skill-creator / skill-ops)./axum-bootstrapScaffolds a Rust axum 0.8 + SeaORM 2.0 + PostgreSQL 16 backend from zero, standalone or apps/api monorepo. House convention: DDD-lite domains with Admin/Client route groups, fail-fast env validation, three utoipa OpenAPI docs with Swagger UI, tracing JSON logs, a Docker image, tests against a real Postgres. Phase 0 decides standalone (Cargo workspace at the repo root) or apps/api in a pnpm monorepo next to packages/contracts. Use when the user wants to start, set up or scaffold a new axum or Rust backend with this stack: "러스트 백엔드 새로 세팅해줘", "axum 프로젝트 만들어줘", "sea-orm 붙여서 rust api 서버 깔아줘", "bootstrap an axum backend", "scaffold a Rust API with SeaORM and Postgres", "set up apps/api in Rust". Do NOT use for: adding a domain to an existing axum project (use axum-domain-module), writing a SeaORM migration (use axum-migration), NestJS or FastAPI backends (nestjs-bootstrap / fastapi-bootstrap), the whole multi-app bootstrap chain (project-setup), or other Rust frameworks such as actix-web, rocket, poem or loco.Other plugins' skills for the same job