With multiple databases configured, working with the rake tasks provided by ActiveRecord can be a little confusing. Some of the tasks support an optional database name suffix (e.g. db:migrate:primary
), some don’t (e.g. db:schema:load
), and some now require it (e.g. db:rollback
as of #38770).
As more tasks need to support multiple databases, we’re going to wind up with a lot of duplication in databases.rake - there are already seven instances of DatabaseTasks.for_each(databases)
. I originally started looking into this because I needed to do a db:schema:load
for only one particular database, so I’d say there’s probably a need to extend multi-db support to more, if not all, of the tasks.
Looking at #38770 above, it seems like we might be OK with breaking changes in the tasks, so I wanted to suggest moving the database name to the second chunk of the task name (db:primary:migrate
instead of db:migrate:primary
) and raising an error for any use of non-namespaced tasks when multi-db support is enabled. This would let us define all the tasks inside a single loop, and also define all tasks for each database, making the interface consistent.
cc: @eileencodes - the multi-db expert. WDYT?