Class: Gitlab::Database::SharedModel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gitlab::Database::SharedModel
show all
- 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, BackgroundOperation::Job, BackgroundOperation::JobCellLocal, BackgroundOperation::Worker, BackgroundOperation::WorkerCellLocal, Partitioning::TableWithoutModel, PgClass, PgDepend, PostgresAutovacuumActivity, PostgresConstraint, PostgresForeignKey, PostgresIndex, PostgresIndexBloatEstimate, PostgresPartition, PostgresPartitionedTable, PostgresSequence, PostgresTableSize, Reindexing::QueuedAction, Reindexing::ReindexAction, LooseForeignKeys::DeletedRecord, Postgresql::DetachedPartition, Postgresql::ReplicationSlot
Constant Summary
collapse
- SHARED_SCHEMAS =
%i[gitlab_shared gitlab_shared_org gitlab_shared_cell_local].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.connection ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/gitlab/database/shared_model.rb', line 51
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
60
61
62
|
# File 'lib/gitlab/database/shared_model.rb', line 60
def connection_pool
connection.pool
end
|
.ensure_connection_set! ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/gitlab/database/shared_model.rb', line 43
def ensure_connection_set!
return if overriding_connection
raise 'Connection not set for SharedModel partition strategy. ' \
'Use SharedModel.using_connection() to set the correct connection. ' \
'Using the default database is dangerous.'
end
|
.using_connection(connection) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/gitlab/database/shared_model.rb', line 18
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
gitlab_schemas = Gitlab::Database.gitlab_schemas_for_connection(connection)
unless gitlab_schemas.nil? || (gitlab_schemas & SHARED_SCHEMAS).present?
raise "Cannot set `SharedModel` to connection from `#{Gitlab::Database.db_config_name(connection)}` " \
"since this connection does not include any of the shared gitlab_schema."
end
self.overriding_connection = connection
yield
ensure
self.overriding_connection = previous_connection
end
|
Instance Method Details
#connection_db_config ⇒ Object
75
76
77
|
# File 'lib/gitlab/database/shared_model.rb', line 75
def connection_db_config
self.class.connection_db_config
end
|