Back to Blog

Rails 6.1 raises error on rollback when using multiple database

on August 12, 2020
This blog is part of our Rails 6.1 series.

Rails 6.1 adds support to handle db:rollback in case of multiple database application.

Prior to this change, on executing db:rollback Rails used to rollback the latest migration from the primary database. If we passed on a [:NAME] option along with to specify the database, we used to get an error. Check out the issue for more details.

Rails 6.0.0

1> rails db:rollback:secondary
2
3rails aborted!
4Don't know how to build task `db:rollback:secondary` (See the list of available tasks with `rails --tasks`)
5Did you mean?  db:rollback

Staring with Rails 6.1, we need to pass the database name along with db:rollback:[NAME] otherwise a RuntimeError is raised.

Rails 6.1.0

1> rails db:rollback
2
3rails aborted!
4You're using a multiple database application. To use `db:migrate:rollback` you must run the namespaced task with a VERSION. Available tasks are db:migrate:rollback:primary and db:migrate:rollback:secondary.
5
6> rails db:rollback:primary
7
8== 20200731130500 CreateTeams: reverting ======================================
9-- drop_table(:teams)
10   -> 0.0060s
11== 20200731130500 CreateTeams: reverted (0.0104s) =============================

Check out the pull request for more details on this.