Skip to content

Draft: Make `finalize_background_migration` to work properly with many DBs

Kamil Trzciński requested to merge support-finalize-migrations into master

This makes the finalize_background_migration when running migration class to restore original connections allowing the application to use ApplicationRecord as a way to access main database.

Running db:migrate will switch ActiveRecord::Base.connection to be any of the databases depending on a migration context.

This naturally breaks all background migrations that do use ApplicationRecord as a way to access :main.

The change introduced here is "a workaround" / "a minimal change" to allow finalize to execute background migration that is normally executed in sidekiq context within a migration context.

Different ways are better described here: #358430 (comment 931712686)

Edited by Kamil Trzciński

Merge request reports