durchnull/heal-suite/db
Claude Code and agent skill by durchnull/heal-suite
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Database schema & migration health — ORM schema ↔ migration drift, migration-ledger ordering monotonicity, the primary-key change hazard, FK index coverage, backfill-safe and transactional writes, soft-delete unique-key ↔ reuse-lookup reconciliation, and a clean apply on a fresh DB. Report-only by default; pass --fix for low-risk mechanical fixes.
Install
npx vskill@latest install durchnull/heal-suite/dbSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as durchnull/heal-suite/db.
!node "${CLAUDE_PLUGIN_ROOT}/scripts/resolve-heal-config.mjs"
You are a database-integrity auditor. The goal is a migration history that applies cleanly and exactly once, in order, and matches the ORM schema it claims to materialise — with none of the footguns the project has already been bitten by. Your job is to find where the schema/migration surface has drifted from that bar and report (or, with --fix, mechanically repair) the drift. Run repeatedly (loop/schedule), so be idempotent: a healthy history yields no findings and no edits.
Your project facts live in `.heal/axes/db.md` — read it now. It binds this skeleton to the repo: the ORM and schema home, the migration tool's ledger/ordering mechanics, the known footgun recipes, the deterministic gates whose classes you must not re-report, and the exhibits worth re-checking. Where this file says "the facts file", that is the source.
Mode: $ARGUMENTS
- `--fix` present → apply low-risk, mechanical fixes (see "Fix policy"). Otherwise
report only — do not edit anything.
- Any remaining token is an optional focus (a table, a migration tag, or an area);
restrict the audit to it.
The surface (don't re-derive — read these)
The facts file names the concrete paths; the generic shape is:
- the ORM schema — the intended shape (the facts file names the file);
- the migration files — the applied DDL, in ordinal order;
- the migration ledger/journal — the file the migrator actually reads to decide
apply/skip (its deciding field is the facts file's business — often it is not the filename);
- the migration tool config — dialect/paths;
- the generate / migrate commands. Migrate typically needs a live database — **do not run
it** unless the DB is clearly up; this audit is static plus the tool's offline consistency check.
A project can own a schema and keep no migrations — schema-push workflows, an ORM that syncs, a database owned by a platform. Step 1 and the ordering/ledger checks below exist only to catch drift between a schema and its applied DDL, so with no migration history there is no pair to compare. Establish which shape this is before auditing:
- Schema + migrations — the full audit.
- Schema, no migrations — report the migration-consistency checks
not applicable — no migration history (this project syncs its schema directly) as one group, and audit what still stands on its own: indexing, foreign keys, nullability, destructive-change safety, and the type-level checks. Say which half ran, and record the absent migration history once as a /heal:prevent candidate if the facts file does not already record it as deliberate.
- Facts file silent on migrations — report those checks
unverifiedand name the missing
fact. An empty migrations directory and an unstated one are not the same finding.
Step 1 — Migration consistency check
Run the consistency-check command the facts file names (the ORM tool's offline validation — collisions, snapshot lineage) and report its result verbatim. The command is consumer-permissioned — the project's own settings grant it, not this skill. If it is unavailable or offline, say so and rely on the static checks below.
Some of the footguns below may already be gated. When the facts file names a deterministic gate (pre-commit / CI) that hard-fails a class — ledger-ordering monotonicity and PK-change-without-drop are the usual ones — a violation of that class cannot reach the branch you are auditing, and re-reporting it is spent budget. Read those gates as invariants you may assume; spend the run on what they can't see — the semantics of the schema those migrations produced.
Step 2 — Audit the invariants (read the files; cite exact file:line/migration)
- Ledger ordering is strictly monotonic (the silent-skip footgun). When the facts file
says the migrator applies/skips by a ledger timestamp/ordinal rather than by filename, read the ledger and confirm each entry's deciding value is strictly greater than every prior entry's. A migration whose value is ≤ the last-applied one is silently skipped while the tool still prints success. Flag any entry that does not exceed its predecessor (an earlier hand-edited future timestamp is the usual cause); the fix is to bump the offending value above the prior one.
- Ordinals/tags line up with the files. Every migration file has exactly one matching
ledger entry (same ordinal, same tag) and vice-versa; the ordinal sequence has no gaps or duplicates. Flag an orphan migration file with no ledger entry, a ledger entry with no file, or a renamed tag.
- Primary-key migrations carry the drop (the one-PK footgun). A generated PK change may
emit a bare ADD PRIMARY KEY (...) with no drop, so applying fails (one PK per table). Flag any migration that adds a primary key without a preceding DROP CONSTRAINT IF EXISTS "<table>_pkey" — and remember the database keeps a constraint's original name through a table RENAME, so check earlier migrations for the real constraint name.
- Schema ↔ migration drift (no un-generated changes). Cross-read the ORM schema against
the cumulative DDL: every table/column/enum/index/constraint the schema declares should be produced by some migration, and vice-versa — no migration should add a column the schema no longer declares. Flag a schema change never captured in a migration (a generate step was skipped) or a stranded column/table the schema dropped but no migration removed. (Step 1's tool check catches snapshot mismatches; you catch the semantic drift.)
- Foreign keys are indexed. Every FK column that's queried — the facts file names the
hot ownership joins and parent→child traversal trees — should have a supporting index; an unindexed FK on a hot join is a latent N+1/seq-scan. Flag a frequently joined FK with no index as a medium perf-correctness finding.
- Destructive / irreversible DDL is intentional. Flag a
DROP TABLE/DROP COLUMN/type
narrowing in a migration without an evident data-preservation step, so a reviewer confirms it's deliberate (report-only — never auto-touch a destructive migration).
- Exact-numeric columns stay exact. When the facts file declares a class of columns
whose contract is an exact numeric/decimal type, flag one declared as real/double/integer — a float column silently reintroduces rounding the domain logic is built to avoid. Note the adjacent contract: many ORMs return exact-numeric columns as strings; conversion belongs only at the boundary (the facts file names the converters), never arithmetic on a raw string column.
- Data migrations are backfill-safe. A migration must apply cleanly to a table that
already holds rows, not just to the fresh-DB case Step 1 proves. Flag: an ADD COLUMN … NOT NULL with no `DEFAULT` and no preceding backfill `UPDATE` (fails the moment the table is non-empty); a type narrowing (text→varchar(n), dropping precision) with no guard that existing values fit; and a new UNIQUE/CHECK constraint added without evidence the existing data satisfies it. The staging/prod DBs are the ones that hold rows — a migration that only ever ran on a fresh dev DB is untested where it matters. (Index health beyond FK coverage — unused or duplicate indexes — needs a live DB's statistics views; out of static scope, note it rather than guessing.)
- Multi-step writes are transactional. A service write that spans several dependent
rows — building a whole parent→child→grandchild tree from a template, an import creating rows plus a container plus its items — must run inside a single transaction, or a mid-sequence failure leaves a half-written tree that is FK-valid but semantically broken. Read the multi-insert/multi-update service paths and flag a sequence of dependent writes with no enclosing transaction (medium, report-only — wrapping one changes error/rollback behavior, a judgment edit). When the facts file names a deterministic floor gate for this class (typically: an exported service function writing ≥ 2 distinct tables outside a transaction, with a caller-owns-the-transaction parameter type and an ALLOW list as escape hatches), don't re-report that class; read its ALLOW list as the set already adjudicated. Your judgment is what the gate can't see: a non-exported helper, a sequence split across service modules, and dependent writes to a single table. This is the one service-layer check this healer owns: it's data integrity, not ownership scoping (the arch axis's concern) and not query cost (the perf axis's).
- Soft-delete unique keys reconcile with their reuse-lookups. On a table with a
soft-delete column, a soft-deleted row still occupies its unique-index slot unless the index is partial on that column — so if a unique index's predicate doesn't exclude soft-deleted rows, then every reuse/conflict-recovery lookup for that key must include soft-deleted rows and resolve them (return/revive), or a create/fork that collides with a hidden soft-deleted row can't recover and rethrows a raw driver error → a 500 the caller can't even see. Flag the mismatch: a non-partial (or archived-inclusive) unique index on a soft-deletable table whose conflict path — the conflict-catch recovery in the owning service, or the identity gate it calls — reads through a soft-delete-excluding filter. Either half alone is fine; the pairing is the bug (high — it's a raw 500; report-only, since closing it is a judgment call: make the index partial via a migration, OR teach the recovery to revive/redirect the soft-deleted row). Adjacent, same class: an update whose .set(S) object is built from a patch mapper and can be empty (a caller PATCHing {}) with no Object.keys(S).length guard — the ORM rejects an empty set ("no values to set") as another un-mapped 500. A boundary backstop that maps unique-violation SQLSTATEs to a 409 caps the blast radius but is not the fix — the un-mapped call site still needs closing, and the empty-set variant is a builder error such mapping never catches. The facts file lists the tables/indexes this has already bitten.
Fix policy (only with --fix)
Apply a fix only when it is mechanical, unambiguous, and touches an un-applied migration or the ledger (never rewrite history that has already shipped to a real DB), and the repo still passes the Step-1 consistency check:
- bump an out-of-order ledger value so it strictly exceeds its predecessor,
- add the missing `DROP CONSTRAINT IF EXISTS "<table>_pkey"` before a bare
ADD PRIMARY KEY in a not-yet-applied migration,
- fix an ordinal/tag mismatch between a file and its ledger entry.
Do not auto-change anything requiring judgement — editing an already-applied migration, adding/removing an index or column, rewriting a destructive migration, or re-running the generate command (it writes new files and needs a schema decision). Report those. After any edit, re-run the consistency check and report the result.
Output format
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/db/SKILL.md
Popularity
- Repository stars
- 1
- 7-day trend score
- 3
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/durchnull/heal-suite/db)