rollback
Undo the most recent applied migration(s) by executing the down() function from each migration file.
Synopsis
bash
bunx d1-eloquent rollback [--db <DB_NAME>] [--remote] [--steps <n>]Options
| Flag | Description |
|---|---|
--db <DB_NAME> | Optional. Auto-detected from wrangler.toml, falls back to 'DB'. |
--local | Run against the local D1 database. This is the default. |
--remote | Run against the Cloudflare-hosted D1 database. |
--steps <n> | Number of migrations to roll back. Defaults to 1. |
Examples
Roll back the most recent migration:
bash
bunx d1-eloquent rollbackRoll back the three most recently applied migrations:
bash
bunx d1-eloquent rollback --steps 3Roll back one migration from the remote database:
bash
bunx d1-eloquent rollback --remoteNotes
- Rollback executes the
down()function from each migration file in reverse order. - Ensure your
down()function correctly reverses every change made byup(). Ifdown()is missing or incomplete, rollback cannot fully restore the prior schema. - After rollback, the migration record is removed from
_migrationsso the migration can be re-applied withmigrate.