From 2054d59bf3b818c70ea85c82f594c9624d511fb6 Mon Sep 17 00:00:00 2001
From: Patrick Bair <pbair@gitlab.com>
Date: Mon, 28 Feb 2022 22:08:45 +0000
Subject: [PATCH] Fix usage of ActiveRecord::Base in importer code

Use the connection from the associated relation class rather than
ActiveRecord::Base when doing an index check.

https://gitlab.com/gitlab-org/gitlab/-/issues/350191
---
 .rubocop_todo/database/multiple_databases.yml     | 1 -
 lib/gitlab/import_export/base/relation_factory.rb | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/.rubocop_todo/database/multiple_databases.yml b/.rubocop_todo/database/multiple_databases.yml
index 69bc0b64a30d5..e390f81f0304a 100644
--- a/.rubocop_todo/database/multiple_databases.yml
+++ b/.rubocop_todo/database/multiple_databases.yml
@@ -20,7 +20,6 @@ Database/MultipleDatabases:
   - lib/gitlab/database.rb
   - lib/gitlab/gitlab_import/importer.rb
   - lib/gitlab/health_checks/db_check.rb
-  - lib/gitlab/import_export/base/relation_factory.rb
   - lib/gitlab/import_export/group/relation_tree_restorer.rb
   - lib/gitlab/legacy_github_import/importer.rb
   - lib/gitlab/seeder.rb
diff --git a/lib/gitlab/import_export/base/relation_factory.rb b/lib/gitlab/import_export/base/relation_factory.rb
index 8a8c74c302d06..53dd6f8cd5508 100644
--- a/lib/gitlab/import_export/base/relation_factory.rb
+++ b/lib/gitlab/import_export/base/relation_factory.rb
@@ -300,7 +300,7 @@ def has_unique_index_on_importable_fk?
           return cache[table_name] if cache.has_key?(table_name)
 
           index_exists =
-            ActiveRecord::Base.connection.index_exists?(
+            relation_class.connection.index_exists?(
               relation_class.table_name,
               importable_foreign_key,
               unique: true)
-- 
GitLab