db-migrate
Generate a database migration file with up and down methods for the described change, then test rollback.
Create a database migration for: $ARGUMENTS
Follow these steps:
Step 1 - Detect the migration framework
Check the project for:
alembic.iniormigrations/env.py- Alembic (SQLAlchemy / Python)db/migrate/directory with Rails-style timestamps - ActiveRecord (Rails)migrations/with*.sqlfiles - raw SQL migrationsknexinpackage.json- Knex.jssequelizeinpackage.json- Sequelizeprisma/migrations/- Prismatypeorminpackage.json- TypeORMflyway.conforV*.sqlfiles - Flywayliquibase.properties- Liquibase
Report which framework was detected before proceeding.
Step 2 - Inspect existing migrations
Read 2-3 recent migration files to understand:
- Naming conventions (timestamp prefix, snake_case description, etc.)
- Code style and patterns used.
- How
upanddownmethods are structured.
Step 3 - Generate the migration file
Create the migration file following the exact naming and structural conventions of the project.
The migration must include:
- Up: the forward migration implementing "$ARGUMENTS".
- Down: a complete rollback that fully reverses the up migration.
For schema changes, consider:
- Adding/dropping columns: include column type, nullable, default value, and constraints.
- Adding indexes: specify columns, uniqueness, and name the index explicitly.
- Adding foreign keys: specify ON DELETE / ON UPDATE behavior.
- Data migrations: use batching if modifying large tables; never lock the whole table.
Step 4 - Show the generated file
Print the full contents of the migration file and its path.
Step 5 - Test the rollback
Run the up migration, then immediately run the down migration, then run the up migration again. Confirm all three steps succeed:
migrate up(or equivalent)migrate down(or equivalent)migrate upagain
If the migration framework is not runnable in the current environment, explain which commands to run manually.
Step 6 - Summary
Report:
- Migration file path.
- What the up migration does.
- What the down migration does.
- Whether rollback was tested successfully.