migration-safety

migration-safety is a skill for Claude Code from latestaiagents/agent-skills. It costs 68 tokens per session (2,505 once invoked), scanned A, original, MIT.

A safety guide for database migrations, which are changes to a database's structure or stored data. It covers backups, environment checks, existing data, partial failures, and risky reset commands.

In plain words
What is it for?
Use it before creating, rerunning, rolling back, or modifying database migrations.
Why use it?
It helps prevent a schema change from deleting or corrupting production data. It also reduces mistakes caused by running a migration against the wrong database.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the safety plugin — 5 skills shipped together , and of ai-safety-guardrails, latestaiagents

Good fit Use it before creating, rerunning, rolling back, or modifying database migrations.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/latestaiagents/agent-skills/migration-safety
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 latestaiagents/agent-skills --skill migration-safety
Clone the repo
git clone --depth 1 https://github.com/latestaiagents/agent-skills

Made for: Claude Code.

Or install safety, the plugin that ships this one along with the rest of its 5 skills.

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 migration-safety

README.md
[![agentmods](https://agentmods.dev/badge/skills/latestaiagents/agent-skills/migration-safety/github.svg)](https://agentmods.dev/skills/latestaiagents/agent-skills/migration-safety)
Your own site
<a href="https://agentmods.dev/skills/latestaiagents/agent-skills/migration-safety"><img src="https://agentmods.dev/badge/skills/latestaiagents/agent-skills/migration-safety/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for migration-safety

Your own site · 80×15
<a href="https://agentmods.dev/skills/latestaiagents/agent-skills/migration-safety"><img src="https://agentmods.dev/badge/skills/latestaiagents/agent-skills/migration-safety.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 68 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,505 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. 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.00068 $0.02505
Opus 5 $0.00034 $0.01252
Sonnet 5 $0.00014 $0.00501
Haiku 4.5 $0.00007 $0.00250

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

Security

Grade A, and why

migration-safety scanned grade A with 1 finding 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.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

execSync('npx prisma migrate deploy');
skills/safety/ai-safety-guardrails/migration-safety/SKILL.md · 410 lines

How it starts

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

Migration Safety

CRITICAL: Migrations can destroy production data. This skill prevents catastrophic data loss.

The Problem This Solves

Real disaster scenarios:

  • Migration fails halfway, rollback deletes all records
  • Re-running migration truncates existing data
  • Column drop removes 50,000 user records
  • Foreign key constraint fails, cascade deletes everything
  • "Fresh migration" on wrong database wipes production

Golden Rules

  1. NEVER run migrations without checking for existing data first
  2. ALWAYS create a backup before ANY migration
  3. NEVER re-run a migration that previously partially completed without investigation
  4. ALWAYS verify you're on the correct database/environment
  5. NEVER trust migrate:fresh or migrate:reset on any database with data

Pre-Migration Checklist

Step 1: Environment Verification

# Check current environment
echo $NODE_ENV
echo $RAILS_ENV
echo $APP_ENV

# Check database connection
# Laravel
php artisan db:show

# Rails
rails db:version

# Node.js (check connection string)
echo $DATABASE_URL

RED FLAGS - STOP IMMEDIATELY:

  • Environment shows "production", "prod", "live"
  • Database URL contains production hostname
  • You're not 100% certain which database you're connected to

Step 2: Check Existing Data

-- Before ANY migration, check what exists
SELECT table_name,
       (SELECT COUNT(*) FROM information_schema.columns
        WHERE table_name = t.table_name) as columns,
       (SELECT reltuples::bigint FROM pg_class
        WHERE relname = t.table_name) as estimated_rows
FROM information_schema.tables t
WHERE table_schema = 'public'
ORDER BY table_name;

Present this to user:

## Current Database State

**Database:** [name]
**Environment:** [env]
**Tables:** [count]
**Total estimated rows:** [count]

| Table | Columns | Estimated Rows |
|-------|---------|----------------|
| users | 15 | 12,450 |
| orders | 23 | 89,234 |
| ... | ... | ... |

⚠️ This migration will affect a database with EXISTING DATA.

Read the full file on GitHub · 410 lines

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 · 410 lines · 68 tokens per session scan A 53cdb40eb4f4

Subscribe to this mod's changes

migration-safety is a skill published in the GitHub repository latestaiagents/agent-skills (5 stars, last pushed 4mo ago), licensed MIT. It adds 68 tokens to every session and 2,505 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.