Skip to content

Add support for creating multi db config for config/database.yml

Thong Kuah requested to merge configure_multi_db_config into main

What does this Merge Request do and why?

In gitlab!64289 (merged), we added option to have separate ci: database in config/database.yml (see also https://docs.gitlab.com/ee/development/database/multiple_databases.html#multiple-databases)

This MR adds support in GDK to automatically generate this.

The default is false for this new setting. There is one (backwards compatible) change to indent the config/database.yml to name the main database main.

For the time being, only ~"group::sharding" engineers will set this to true. We will be make this default enabled for all engineers in the future when the decomposition epic is further along

Related issue: gitlab#333527 (closed), &6168 (closed)

Manual QA

Before (on main branch):

development:
  adapter: postgresql
  encoding: unicode
  database: gitlabhq_development
  host: /Users/tkuah/code/ee-gdk/postgresql
  port: 5432
  pool: 10
  prepared_statements: false
  variables:
    statement_timeout: 120s

test: &test
  adapter: postgresql
  encoding: unicode
  database: gitlabhq_test
  host: /Users/tkuah/code/ee-gdk/postgresql
  port: 5432
  pool: 10
  prepared_statements: false
  variables:
    statement_timeout: 120s

After, with config disabled

development:
  main:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_development
    host: /Users/tkuah/code/ee-gdk/postgresql
    port: 5432
    pool: 10
    prepared_statements: false
    variables:
      statement_timeout: 120s

test: &test
  main:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_test
    host: /Users/tkuah/code/ee-gdk/postgresql
    port: 5432
    pool: 10
    prepared_statements: false
    variables:
      statement_timeout: 120s

The rails app works after GDK restart.

After, with config enabled

make gitlab/config/database.yml with the following gdk.yml:

gitlab:
  rails:
    multi_db_config: true
development:
  main:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_development
    host: /Users/tkuah/code/ee-gdk/postgresql
    port: 5432
    pool: 10
    prepared_statements: false
    variables:
      statement_timeout: 120s
  ci:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_development_ci
    migrations_paths: db/ci_migrate
    host: /Users/tkuah/code/ee-gdk/postgresql
    port: 5432
    pool: 10
    prepared_statements: false
    variables:
      statement_timeout: 120s

test: &test
  main:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_test
    host: /Users/tkuah/code/ee-gdk/postgresql
    port: 5432
    pool: 10
    prepared_statements: false
    variables:
      statement_timeout: 120s
  ci:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_test_ci
    migrations_paths: db/ci_migrate
    host: /Users/tkuah/code/ee-gdk/postgresql
    port: 5432
    pool: 10
    prepared_statements: false
    variables:
      statement_timeout: 120s

The rails app works after GDK restart.

Merge Request checklist

  • This change is backward compatible. If not, please include steps to communicate to our users.
  • Tests added for new functionality. If not, please raise Issue to follow-up.
  • Documentation added/updated, if needed.
  • [-] gdk doctor test added, if needed.
  • [-] Add the ~highlight label if this MR should be included in the CHANGELOG.md.
Edited by Thong Kuah

Merge request reports