Rollback a migration by version rolls back the latest migration if the version isn't found

I meant to run a rollback on a different database, but didn’t specify the name of the database name like so: rake db:rollback VERSION=20200509010531 Instead of an error saying it wasn’t finding that version, the last migration in the migrations directory was rolled back. Caused me a little WTF.

1 Like

I work with @leskat. My process for rolling back migrations on our secondary db is inevitably something like:

  1. bin/rails db:rollback
  2. OOPS. uh, bin/rails db:rollback --database secondary_db_name ?
  3. Hmmmmm, right, it’s that one I can never remember. bin/rake -T | grep db
  4. UGHHHHHH why is the one I can never remember not actually listed with bin/rake -T
  5. db:migrate:down IS listed, and feels close, but I know I need to put secondary_db_name in there somewhere. Is it bin/rails db:migrate:secondary_db_name:down VERSION=#?
  6. No. It is the other one. Drat. At least I got a useful error this time.
  7. successfully running bin/rails db:migrate:down:secondary_db_name VERSION=#