Loading
Add the gitlab_mr_diff schema and mr_diff connection
What does this MR do and why?
Adds the gitlab_mr_diff schema, the mr_diff database connection and MrDiffApplicationRecord. This is the first step in moving the merge request diff tables to their own database.
It changes nothing at runtime:
- The
mr_diffconnection usesfallback_database: main, andMrDiffApplicationRecordonly callsconnects_towhenmr_diffis configured. Without it, the model usesmain's connection pool. - No tables use
gitlab_mr_diffyet. The tables move in a later merge request.
Not included yet:
- The
config/database.ymltemplate formr_diffand the CI variable that turns it on in CI. https://gitlab.com/gitlab-org/gitlab/-/work_items/635395 tracks them. - The hardcoded database lists (the
gitlab:db:migration_testingtasks,gitlab:db:truncate_legacy_tables:mr_diff,TablesTruncate,schema_load_fix,spec/support/multiple_databases.rband loose foreign key turbo mode with its ops flag). They only run once CI configuresmr_diff, so they go in the same merge request as the template. - The background migration and background operation workers, the Sidekiq duration limit, and the Prometheus health indicator case. They only matter once
mr_diffhas its own connection, and the workers' cron entries and the Sidekiq limit would add work on every installation before then.
References
- https://gitlab.com/gitlab-org/gitlab/-/work_items/635350
- Step-by-step checklist for a new decomposed database
How to set up and validate locally
-
With no
mr_diffentry inconfig/database.yml, check the fallback in a Rails console:Gitlab::Database.has_config?(:mr_diff) # => false MrDiffApplicationRecord.connection_db_config.name # => "main" Gitlab::Database.gitlab_schemas_for_connection(ApplicationRecord.connection).include?(:gitlab_mr_diff) # => true -
Run the specs that check connection and schema definitions:
bin/rspec spec/lib/gitlab/database_spec.rb spec/lib/gitlab/database/gitlab_schema_spec.rb spec/lib/gitlab/database/database_connection_info_spec.rb
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Patrick Bajao