Skip to content

Use native AR multiple database support for Gitlab::Database::SharedModel models

Background

We find that we have to use Gitlab::Database::SharedModel.using_connection in various places, such as spec/lib/gitlab/database/reindexing/coordinator_spec.rb

The issue

It is not predictable when we run LooseForeignKeys::DeletedRecord.where which database will be accessed.

Proposal

Status 2023-04-03

We should do this major technical debt if we ever intend to do Change `GitLab::LoadBalancing` to use a native ... (#296870 - closed), or we find that we add more decomposition.

Proposal

Refactor to switch these models to use native AR multiple database support

  1. app/models/loose_foreign_keys/deleted_record.rb:class LooseForeignKeys::DeletedRecord < Gitlab::Database::SharedModel
  2. app/models/postgresql/detached_partition.rb: class DetachedPartition < ::Gitlab::Database::SharedModel
  3. app/models/postgresql/replication_slot.rb: class ReplicationSlot < Gitlab::Database::SharedModel
  4. lib/gitlab/database/async_indexes/postgres_async_index.rb: class PostgresAsyncIndex < SharedModel
  5. lib/gitlab/database/background_migration_job.rb: class BackgroundMigrationJob < SharedModel
  6. lib/gitlab/database/each_database.rb: if model < ::Gitlab::Database::SharedModel
  7. lib/gitlab/database/partitioning.rb: class TableWithoutModel < Gitlab::Database::SharedModel
  8. lib/gitlab/database/pg_class.rb: class PgClass < SharedModel
  9. lib/gitlab/database/postgres_foreign_key.rb: class PostgresForeignKey < SharedModel
  10. lib/gitlab/database/postgres_index.rb: class PostgresIndex < SharedModel
  11. lib/gitlab/database/postgres_index_bloat_estimate.rb: class PostgresIndexBloatEstimate < SharedModel
  12. lib/gitlab/database/postgres_partition.rb: class PostgresPartition < SharedModel
  13. lib/gitlab/database/postgres_partitioned_table.rb: class PostgresPartitionedTable < SharedModel
  14. lib/gitlab/database/reindexing/queued_action.rb: class QueuedAction < SharedModel
  15. lib/gitlab/database/reindexing/reindex_action.rb: class ReindexAction < SharedModel
Edited by Thong Kuah