Fix `lib/gitlab/database/migration_helpers.rb` to support many databases
Currently lib/gitlab/database/migration_helpers.rb
very often uses Gitlab::Database::
or Gitlab::Database.
which is not many databases aware. Since MigrationHelpers
are included into ActiveRecord::Migration
we should always use #connection
method instead to fetch a currently established connection instead
of using ActiveRecord::Base
.
Technically, the usage of ActiveRecord::Base
should work, but it is flakky and not properly documented.
The proper way is to ensure that we never use ActiveRecord::Base.connection
as we cannot guarantee
when and how the migration is executed. The usage of ActiveRecord::Base.connection
is internal detail
of migration execution of Rails.
This is especially problematic after the https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66288/diffs#note_638354292
, where the .main
might not truly return details
of a main database, but actually established, and effectively be confusing as for the execution.