Skip to content

Switch ActsOnTaggable model's DB connection to ci database

Thong Kuah requested to merge switch_acts_as_taggable_db_connection into master

What does this MR do and why?

Switch ActsOnTaggable model's DB connection to ci database

We need to do two things:

  1. Override the LB connection (which is based off the base class's LB)
  2. Override the connection_specification_name for other Rails connection methods that LB does not handle such as retrieve_connection

The specs from https://gitlab.com/gitlab-org/gitlab/-/blob/876909a20993d054a88c254b74a24a28e23042dd/spec/models/ci/runner_spec.rb#L1032 should cover this, in that it ensures that a SQL query joining from ci_runners to tags runs correctly.

Related issue: #343747 (closed)

Screenshots or screen recordings

Before:

[1] pry(main)> ActsAsTaggableOn::Tag.connection.execute('select current_database()').first
   (0.4ms)  select current_database() /*application:console,db_config_name:main,line:(pry):1:in `__pry__'*/
=> {"current_database"=>"gitlabhq_development"}
[2] pry(main)> ActsAsTaggableOn::Tag.retrieve_connection.execute('select current_database()').first
   (0.9ms)  select current_database() /*application:console,db_config_name:main,line:(pry):2:in `__pry__'*/
=> {"current_database"=>"gitlabhq_development"}

After, with ci: database in config/database.yml:

[1] pry(main)> ActsAsTaggableOn::Tag.connection.execute('select current_database()').first
   (0.4ms)  select current_database() /*application:console,db_config_name:ci,line:(pry):1:in `__pry__'*/
=> {"current_database"=>"gitlabhq_development_ci"}
[2] pry(main)> ActsAsTaggableOn::Tag.retrieve_connection.execute('select current_database()').first
   (1.0ms)  select current_database() /*application:console,db_config_name:ci,line:(pry):2:in `__pry__'*/
=> {"current_database"=>"gitlabhq_development_ci"}

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Thong Kuah

Merge request reports

Loading