Class: Gitlab::Database::SharedModel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gitlab::Database::SharedModel
- Includes:
- IgnorableColumns
- Defined in:
- lib/gitlab/database/shared_model.rb
Overview
This abstract class is used for models which need to exist in multiple de-composed databases.
Direct Known Subclasses
AsyncConstraints::PostgresAsyncConstraintValidation, AsyncIndexes::PostgresAsyncIndex, BackgroundMigration::BatchedJob, BackgroundMigration::BatchedJobTransitionLog, BackgroundMigration::BatchedMigration, BackgroundMigrationJob, Partitioning::TableWithoutModel, PgClass, PgDepend, PostgresAutovacuumActivity, PostgresConstraint, PostgresForeignKey, PostgresIndex, PostgresIndexBloatEstimate, PostgresPartition, PostgresPartitionedTable, PostgresSequence, PostgresTableSize, Reindexing::QueuedAction, Reindexing::ReindexAction, LooseForeignKeys::DeletedRecord, Postgresql::DetachedPartition, Postgresql::ReplicationSlot
Class Method Summary collapse
- .connection ⇒ Object
-
.connection_pool ⇒ Object
in case the connection has been switched with using_connection.
- .using_connection(connection) ⇒ Object
Instance Method Summary collapse
Class Method Details
.connection ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/gitlab/database/shared_model.rb', line 41 def connection if connection = self.overriding_connection connection else super end end |
.connection_pool ⇒ Object
in case the connection has been switched with using_connection
50 51 52 |
# File 'lib/gitlab/database/shared_model.rb', line 50 def connection_pool connection.pool end |
.using_connection(connection) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gitlab/database/shared_model.rb', line 16 def using_connection(connection) previous_connection = self.overriding_connection unless previous_connection.nil? || previous_connection.equal?(connection) raise "Cannot change connection for Gitlab::Database::SharedModel "\ "from '#{Gitlab::Database.db_config_name(previous_connection)}' "\ "to '#{Gitlab::Database.db_config_name(connection)}'" end # connection might not be yet adopted (returning nil, and no gitlab_schemas) # in such cases it is fine to ignore such connections gitlab_schemas = Gitlab::Database.gitlab_schemas_for_connection(connection) unless gitlab_schemas.nil? || gitlab_schemas.include?(:gitlab_shared) raise "Cannot set `SharedModel` to connection from `#{Gitlab::Database.db_config_name(connection)}` " \ "since this connection does not include `:gitlab_shared` schema." end self.overriding_connection = connection yield ensure self.overriding_connection = previous_connection end |
Instance Method Details
#connection_db_config ⇒ Object
65 66 67 |
# File 'lib/gitlab/database/shared_model.rb', line 65 def connection_db_config self.class.connection_db_config end |