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), or we find that we add more decomposition.
Proposal
Refactor to switch these models to use native AR multiple database support
- app/models/loose_foreign_keys/deleted_record.rb:class LooseForeignKeys::DeletedRecord < Gitlab::Database::SharedModel
- app/models/postgresql/detached_partition.rb: class DetachedPartition < ::Gitlab::Database::SharedModel
- app/models/postgresql/replication_slot.rb: class ReplicationSlot < Gitlab::Database::SharedModel
- lib/gitlab/database/async_indexes/postgres_async_index.rb: class PostgresAsyncIndex < SharedModel
- lib/gitlab/database/background_migration_job.rb: class BackgroundMigrationJob < SharedModel
- lib/gitlab/database/each_database.rb: if model < ::Gitlab::Database::SharedModel
- lib/gitlab/database/partitioning.rb: class TableWithoutModel < Gitlab::Database::SharedModel
- lib/gitlab/database/pg_class.rb: class PgClass < SharedModel
- lib/gitlab/database/postgres_foreign_key.rb: class PostgresForeignKey < SharedModel
- lib/gitlab/database/postgres_index.rb: class PostgresIndex < SharedModel
- lib/gitlab/database/postgres_index_bloat_estimate.rb: class PostgresIndexBloatEstimate < SharedModel
- lib/gitlab/database/postgres_partition.rb: class PostgresPartition < SharedModel
- lib/gitlab/database/postgres_partitioned_table.rb: class PostgresPartitionedTable < SharedModel
- lib/gitlab/database/reindexing/queued_action.rb: class QueuedAction < SharedModel
- lib/gitlab/database/reindexing/reindex_action.rb: class ReindexAction < SharedModel
Edited by Thong Kuah