Skip to content

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

FlagDescription
--db <DB_NAME>Optional. Auto-detected from wrangler.toml, falls back to 'DB'.
--localRun against the local D1 database. This is the default.
--remoteRun 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 rollback

Roll back the three most recently applied migrations:

bash
bunx d1-eloquent rollback --steps 3

Roll back one migration from the remote database:

bash
bunx d1-eloquent rollback --remote

Notes

  • Rollback executes the down() function from each migration file in reverse order.
  • Ensure your down() function correctly reverses every change made by up(). If down() is missing or incomplete, rollback cannot fully restore the prior schema.
  • After rollback, the migration record is removed from _migrations so the migration can be re-applied with migrate.

Released under the MIT License.