database-migration-expert
Skill30 starsChanged 4 days agoApache-2.0View on GitHub
Manages database schema migrations, seed data scripts, and table versioning in Python backends (Alembic, SQL). Use this skill when asked to change DB schemas, write migrations, or write seeding scripts.
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Adding NOT NULL columns: Never add NOT NULL without a default value in one step.
- Very specific: line 27
Adding Indexes: Use concurrent index creation (CREATE INDEX CONCURRENTLY in Postgres) to prevent locking table reads/writes.
- Distinctive: line 28
Renaming Columns: Never rename a column directly.
- Very specific: line 36
Reversibility Requirement: Ensure the downgrade() function completely and cleanly restores the previous schema state without orphaned …
- Very specific: line 39
Write data seeds with upsert semantics (ON CONFLICT DO UPDATE or checking existing keys) so they can be run multiple times safely.
- Distinctive: line 40
Test both directions locally: upgrade to head, verify schema, downgrade one step, and re-upgrade.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Database Migration Expert Skill
Overview
This skill guides the safe, zero-downtime evolution of relational database schemas and data seeding pipelines. It acts as a Database Administrator and Data Reliability Engineer, ensuring that every schema modification preserves data integrity, avoids destructive table locks, implements clean reversibility, and supports continuous deployment without service outages.
When to Use
Trigger Scenarios
- Creating, reviewing, or executing schema migrations (Alembic, SQL DDL).
- Adding new columns, indexes, foreign keys, or table constraints to existing databases.
- Executing phased column renames or type migrations using expand-contract patterns.
- Authoring idempotent database seeding and fixture scripts.
When NOT to Use
- Application database query tuning: Route to
sql-query-optimizationorbigquery-query-optimization. - General application backend logic: Route to
python-expertorfastapi-expert. - System-level architectural boundaries: Route to
senior-architect-engineering.
Process
Phase 1: Pre-Migration Lock & Safety Analysis
- Inspect proposed changes against production locking risks:
- Adding NOT NULL columns: Never add
NOT NULLwithout a default value in one step; follow expand-contract (add nullable, backfill data, add constraint). - Adding Indexes: Use concurrent index creation (
CREATE INDEX CONCURRENTLYin Postgres) to prevent locking table reads/writes. - Renaming Columns: Never rename a column directly; create new column, double-write, migrate, and clean up.
- Adding NOT NULL columns: Never add
Phase 2: Migration Authoring & Autogeneration Guard
- Generate the migration revision:
alembic revision --autogenerate -m "add_user_status_column" - Autogeneration Guard: Manually audit the generated Python migration script. Autogenerate often misses custom constraints, enums, or index variants.
- Reversibility Requirement: Ensure the
downgrade()function completely and cleanly restores the previous schema state without orphaned artifacts.
Phase 3: Idempotent Seeding & Dry-Run
- Write data seeds with upsert semantics (
ON CONFLICT DO UPDATEor checking existing keys) so they can be run multiple times safely. - Test both directions locally: upgrade to head, verify schema, downgrade one step, and re-upgrade.
Usage
Migration Commands
# Generate auto migration
alembic revision --autogenerate -m "describe_change"
# Apply migrations
alembic upgrade head
# Test downgrade safety
alembic downgrade -1
alembic upgrade headExample Prompts
- "Write an Alembic migration to add an email verification timestamp to users without locking the table in production."
- "Design a safe expand-and-contract migration strategy to rename the 'amount' column to 'amount_cents'."
- "Create an idempotent seeding script for system permissions that can run safely in CI and staging."
Host Execution Instructions
- Claude Code: Generate and edit Alembic scripts, then run migrations against local dev databases via bash.
- Antigravity: Audit migration files and verify both upgrade and downgrade paths execute cleanly.
Red Flags
- Adding a
NOT NULLcolumn without a default to a populated table in production. - Leaving
downgrade()aspassor throwingNotImplementedError. - Direct
ALTER TABLE ... RENAME COLUMNon active high-traffic tables. - Non-idempotent seed files that crash or produce duplicate rows when rerun.
- Running DDL transactions without setting appropriate lock timeouts.
Verification
- Migration script passes manual inspection; autogeneration verified.
- Both
upgradeanddowngradeexecute cleanly and reversibly on local/staging environments. - Heavy index creations specify concurrent or non-blocking creation modes.
- Seeding scripts execute idempotently without primary key or unique constraint violations.
References
For safe migration patterns, expand-contract templates, and zero-downtime checklists:
- Database Migration & Schema Design Reference
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adversarial-challengerSkill
- agent-metricsSkill
- bigquery-query-optimizationSkill
- blackbox-testerSkill
- build-and-ci-gatesSkill
- cdc-scd-patternsSkill
- code-criticSkill
- code-implementerSkill
- code-smells-expertSkill
- commit-expertSkill
- compliance-verifierSkill
- context-captureSkill
- context-restoreSkill
- design-spec-expertSkill
- documentation-expertSkill
- flutter-architecture-decisionsSkill
- flutter-performance-profilingSkill
- flutter-release-engineeringSkill
- flutter-review-checklistSkill
- flutter-senior-orchestrationSkill
- flutter-test-strategySkill
- flutter-upgrade-migrationSkill
- gcp-data-engineeringSkill
- guidelines-karpathySkill
- loop-engineeringSkill
- performance-scalabilitySkill
- product-analystSkill
- pull-request-expertSkill
- python-expertSkill
- qa-testerSkill
- refactoring-code-expertSkill
- repo-researchSkill
- security-auditSkill
- senior-architect-engineeringSkill
- senior-dev-orchestratorSkill
- sql-query-optimizationSkill
- test-driven-developmentSkill
- testing-expertSkill
- ui-ux-designerSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

