rollback
Undo the most recent applied migration(s) by executing the down() function from each migration file.
Synopsis
bash
npx @orphnet/d1-eloquent rollback --db <DB_NAME> [--local | --remote] [--steps <n>]Options
| Flag | Description |
|---|---|
--db <DB_NAME> | Required. The D1 binding name defined in wrangler.toml. |
--local | Run against the local D1 database. Default when neither flag is provided. |
--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
npx @orphnet/d1-eloquent rollback --db MY_DB --localRoll back the three most recently applied migrations:
bash
npx @orphnet/d1-eloquent rollback --db MY_DB --local --steps 3Roll back one migration from the remote database:
bash
npx @orphnet/d1-eloquent rollback --db MY_DB --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.