Skip to content

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

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 (Back 2025-01-01)

Merge request reports

Loading