Skip to content

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

FlagDescription
--db <DB_NAME>Required. The D1 binding name defined in wrangler.toml.
--localRun against the local D1 database. Default when neither flag is provided.
--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
npx @orphnet/d1-eloquent rollback --db MY_DB --local

Roll back the three most recently applied migrations:

bash
npx @orphnet/d1-eloquent rollback --db MY_DB --local --steps 3

Roll back one migration from the remote database:

bash
npx @orphnet/d1-eloquent rollback --db MY_DB --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.