Module: Gitlab::Database::EachDatabase
- Defined in:
- lib/gitlab/database/each_database.rb
Class Method Summary collapse
- .each_connection(only: nil, include_shared: true) ⇒ Object
- .each_model_connection(models, only_on: nil, &blk) ⇒ Object
Class Method Details
.each_connection(only: nil, include_shared: true) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gitlab/database/each_database.rb', line 7 def each_connection(only: nil, include_shared: true) selected_names = Array.wrap(only) base_models = select_base_models(selected_names) base_models.each_pair do |connection_name, model| next if !include_shared && Gitlab::Database.db_config_share_with(model.connection_db_config) connection = model.connection with_shared_connection(connection, connection_name) do yield connection, connection_name end end end |
.each_model_connection(models, only_on: nil, &blk) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gitlab/database/each_database.rb', line 22 def each_model_connection(models, only_on: nil, &blk) selected_databases = Array.wrap(only_on).map(&:to_sym) models.each do |model| # If model is shared, iterate all available base connections # Example: `LooseForeignKeys::DeletedRecord` if model < ::Gitlab::Database::SharedModel with_shared_model_connections(model, selected_databases, &blk) else with_model_connection(model, selected_databases, &blk) end end end |