guarded-db-migration

guarded-db-migration is a skill for Claude Code, Codex from dirtybits/agent-skills. It costs 101 tokens per session (1,531 once invoked), scanned A, original, MIT.

A cautious workflow for changing the structure of a production database, such as adding tables, columns, or indexes. A database migration is a planned change to that structure.

In plain words
What is it for?
Use it to plan, guard, rehearse, and verify schema migrations, especially when working with live data or a disposable copy of a production database.
Why use it?
It helps avoid running risky changes against the wrong database and separates safe startup changes from one-time operations that may fail on existing data.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to plan, guard, rehearse, and verify schema migrations, especially when working with live data or a disposable copy of a production database.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/dirtybits/agent-skills/guarded-db-migration
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add dirtybits/agent-skills --skill guarded-db-migration
Clone the repo
git clone --depth 1 https://github.com/dirtybits/agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for guarded-db-migration

README.md
[![agentmods](https://agentmods.dev/badge/skills/dirtybits/agent-skills/guarded-db-migration.svg)](https://agentmods.dev/skills/dirtybits/agent-skills/guarded-db-migration)
Your own site
<a href="https://agentmods.dev/skills/dirtybits/agent-skills/guarded-db-migration"><img src="https://agentmods.dev/badge/skills/dirtybits/agent-skills/guarded-db-migration.svg" alt="Measured on agentmods" height="20"></a>
Per session 101 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,531 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00101 $0.01531
Opus 5 $0.00051 $0.00766
Sonnet 5 $0.00020 $0.00306
Haiku 4.5 $0.00010 $0.00153

Measured 7d ago against content hash 298197ca10a4, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

guarded-db-migration scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 7d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/guarded-db-migration/SKILL.md · 87 lines

How it starts

The opening of the file, as written. The whole thing — 87 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Guarded DB Migration

Why this skill exists

The two classic agent-caused database incidents are: (1) risky DDL placed in a request-time schema initializer, so the first failure takes down every route that touches the table; and (2) a migration script pointed at the wrong database — a legacy project, a teammate's branch, production instead of staging — because the connection string was ambient. Both are fully preventable with three habits: the additive/guarded split, the expected-host guard, and a rehearsal on a disposable copy of production.

1. The additive/guarded split (decide where the DDL lives)

Runtime schema initializers (code that runs CREATE TABLE IF NOT EXISTS on boot or first request) may contain only additive, race-tolerant, cannot-fail-on-live-data statements:

  • CREATE TABLE IF NOT EXISTS, CREATE INDEX IF NOT EXISTS (non-unique), ADD COLUMN IF NOT EXISTS
  • Idempotent backfills that tolerate concurrent execution

Everything that can fail on live data goes in a guarded one-shot script — never in the initializer:

  • CREATE UNIQUE INDEX (fails on existing duplicates)
  • DROP anything, ALTER ... DROP CONSTRAINT, primary-key swaps
  • Backfills that assume exclusive access or specific data shape
  • Anything requiring a duplicate scan or data repair first

Rule of thumb: if the statement could throw because of the data (not just the schema), it is one-shot-script material.

2. The guarded one-shot script pattern

Write the migration as a standalone script (e.g. scripts/<name>-migration.ts) with two subcommands:

<script> preflight   # read-only: reports duplicates/violations/row counts; exit nonzero if migrate would fail
<script> migrate     # performs the DDL, in order, inside the smallest safe transaction scope

Non-negotiable guards in migrate:

  1. Expected-host guard. The script takes EXPECTED_DATABASE_HOST (or equivalent) and refuses to run unless it matches the host parsed from DATABASE_URL. This converts "wrong ambient connection string" from an incident into an error message. Never default it; never allow a bypass flag.
  2. Preflight-first. migrate re-runs the preflight checks internally before DDL — the world may have changed since you ran preflight manually.
  3. Idempotence or a clear refusal. Running migrate twice must either be a no-op or fail loudly before touching anything.
  4. Print everything. Target host, database, each statement as it runs, and a post-run verification summary. The transcript is the evidence.

Read the full file on GitHub · 87 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 7d ago First seen · 87 lines · 101 tokens per session scan A 298197ca10a4

Subscribe to this mod's changes

guarded-db-migration is a skill published in the GitHub repository dirtybits/agent-skills (2 stars, last pushed 1mo ago), licensed MIT. It adds 101 tokens to every session and 1,531 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

database-patterns

Database design and migration patterns for Alembic migrations, schema design (SQL/NoSQL), and database versioning. Use when creating migrations, designing schemas, normalizing data, managing database versions, or handling schema drift.

yonatangross/orchestkit · 49 tokens

Drizzle ORM Testing

Testing patterns for Drizzle ORM covering migration testing, query builder testing, transaction testing, and database integration testing with PostgreSQL, SQLite, and MySQL.

PramodDutta/qaskills · 36 tokens

forgetful-cli-setup

Set up the Forgetful CLI and connect from a terminal — install, local or remote mode, auth, and verification. Use when connecting a human or headless agent via shell, wiring CI with token auth, or operating a local server (serve, database selection, feature flags, re-embedding). Also covers the machine contract…

ScottRBK/forgetful · 84 tokens

srtd-cli

This skill should be used when the user mentions "srtd", "sql templates", "migrations-templates", "live reload sql", "supabase functions", when working with files in supabase/migrations-templates/, when .buildlog.json or srtd.config.json is detected, or when writing Postgres functions/views/triggers for Supabase.

t1mmen/srtd · 75 tokens

neon

Use when you have picked Neon (serverless Postgres) and need to connect correctly from a serverless or edge runtime, wire database branching into dev, preview and CI, or stop being burned by scale-to-zero cold starts and pooler limits — including choosing HTTP versus WebSocket connections and pooled versus direct…

ericrisco/rsc-harness · 93 tokens

postgresdb

Use when PostgreSQL engine behaviour decides the answer — schema and type design, index choice, reading EXPLAIN on a slow query, zero-downtime DDL and backfills, or ops (roles, RLS, pooling, vacuum, partitioning, PITR). PG16, ORM-agnostic. NOT portable query logic (that is sql), NOT a managed provider's platform…

ericrisco/rsc-harness · 91 tokens