Agent skill
db-migrate
Create, validate, and manage database migrations across any framework. Auto-detects Alembic, Prisma, Knex, Django, Flyway, Rails, and more.
Install this agent skill to your Project
npx add-skill https://github.com/mgiovani/cc-arsenal/tree/main/skills/db-migrate
Metadata
Additional technical details for this skill
- author
- mgiovani
- version
- 1.0.0
SKILL.md
DB Migrate
Cross-Platform AI Agent Skill This skill works with any AI agent platform that supports the skills.sh standard.
Create, validate, and run database migrations across any framework. Auto-detects the migration tool from project files.
Anti-Hallucination Guidelines
CRITICAL: Migration operations can be irreversible in production:
- Detect before acting — Always scan for marker files before running any command
- Never invent commands — Only use commands listed in the detection table or discovered in project docs
- Warn on destructive operations — Always flag DROP, TRUNCATE, or irreversible schema changes
- Dry-run first — Use
--dry-runmode when supported by the framework - Read existing migrations — Check naming conventions before creating new ones
Workflow
Phase 1: Detect Framework
Scan for marker files to identify the migration framework:
# Check for common marker files
ls alembic.ini 2>/dev/null
ls prisma/schema.prisma 2>/dev/null
ls knexfile.* 2>/dev/null
ls flyway.conf 2>/dev/null
ls db/migrate/ 2>/dev/null
ls manage.py 2>/dev/null
ls atlas.hcl 2>/dev/null
Also check:
package.jsonforknex,db-migrate,sequelize,typeormdependenciespyproject.toml/requirements.txtforalembic,sqlalchemyGemfileforactiverecord
If multiple frameworks detected, ask user which one to use. If none detected, ask user to specify.
Refer to references/framework-commands.md for the full detection table and per-framework commands.
Phase 2: Parse Arguments
Determine operation mode from $ARGUMENTS:
create(or no argument): Create a new migration filestatus: Show pending and applied migrationsvalidate: Check rollback scripts, naming conventions, index coverage
If --name <name> provided, use it for migration name. Otherwise ask for a descriptive name.
If --dry-run provided, show what would be created/run without executing.
Phase 3: Execute Operation
create — New Migration
- Check naming conventions in existing migrations (Glob
migrations/,db/migrate/) — infer pattern - Generate timestamp prefix:
date +%Y%m%d%H%M%S - Run framework-native CLI to create the migration file
- Verify file was created — read and display it to the user
- If autogenerate is available (Alembic, Prisma): generate from schema diff
After creation, remind user to:
- Review the generated migration for correctness
- Add rollback/down script if not auto-generated
- Add indexes for any new foreign keys
status — Pending Migrations
Run the framework's status command and display:
- Applied migrations (with timestamps)
- Pending migrations (not yet applied)
- Current database schema version
validate — Migration Quality Check
Check the following:
- Rollback exists: Every
upmigration has adownscript (warn if missing) - Naming convention: All files follow the project's timestamp + description pattern
- Foreign key indexes: Grep for
REFERENCESor foreign key declarations without correspondingCREATE INDEX - Destructive operations: Grep for
DROP TABLE,DROP COLUMN,TRUNCATE— flag each one - Data migrations vs schema migrations: Warn if both data and schema changes exist in one file
Phase 4: Safety Checks
Always run these before finalizing a create operation:
Destructive operation detection:
grep -iE "DROP TABLE|DROP COLUMN|TRUNCATE|DELETE FROM" <migration_file>
If found: warn user, require explicit confirmation to proceed.
Missing index check:
grep -iE "REFERENCES|foreign_key|FK_" <migration_file>
If foreign keys present, check for corresponding index creation.
Rollback verification:
- Check if the migration has both up and down sections
- For autogenerated migrations (Prisma, Alembic): verify the shadow database check passes
Phase 5: Report
Display a summary of what was created or checked:
- File path of new migration
- Migration name and timestamp
- Any warnings (destructive ops, missing rollbacks, missing indexes)
- Next steps (apply with
<command>, rollback with<command>)
Argument Parsing
create: Create a new migration (default if no subcommand given)status: Show migration statusvalidate: Validate existing migrations--name <name>: Migration description for the filename--dry-run: Show what would happen without executing
Important Notes
- Always review auto-generated migrations before applying — they may include unintended changes
- Rollback scripts are required for production safety; warn loudly if missing
- Never run migrations directly against production without a backup
- Prisma shadow database: Prisma dev migrations use a shadow DB; ensure
DATABASE_URLis not production - Transaction wrapping: Ensure migrations run in transactions for atomicity
Examples
# Create a new migration
/db-migrate create --name add_users_table
# Check pending migrations
/db-migrate status
# Validate migration quality
/db-migrate validate
# Create without executing (preview)
/db-migrate create --name drop_legacy_column --dry-run
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
gh-daily
Generate standup reports from GitHub Issues activity and git history.
inject-nextjs-docs
Run the Next.js agents-md codemod to inject compressed framework documentation into the current project's CLAUDE.md or AGENTS.md. This skill should be used when a user wants to add Next.js framework docs to their project for AI coding agents, run the Vercel agents-md codemod, or improve AI agent performance on Next.js projects.
git-sync
Sync current branch with base branch using merge (default) or rebase. Handles fork sync, conflict detection, and stash management.
git-release
Create semantic version releases with automated changelog generation from conventional commits. This skill should be used when users want to create a release, tag a version, generate a changelog, bump version numbers, or publish a GitHub release.
forge-dev
Implement user stories with attention to acceptance criteria and code quality.
fix-bug
Fix bugs using test-driven debugging and root cause analysis. Activates when users want to fix a bug, debug an issue, resolve an error, or investigate failing tests.
Didn't find tool you were looking for?