Skip to content

Support the configuration of JH separate database

xfyuan请求将3644-support-jh-separate-database合并到main-jh

What does this MR do and why?

Related issue: https://jihulab.com/gitlab-cn/gitlab/-/issues/3644

Use Rails multiple databases feature to implement JH database support.

This MR is based on the Upstream MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/133566

Reference

Implementations

Gitlab Rails

  • config database.yml with :jh database
  • add JH::ApplicationRecord as base class for JH models
  • add JH::NamespacedModelName mixin to preserve model_name JH models
  • introduce :gitlab_jh schema similar to the :gitlab_geo to deal with SQL cross-joins and cross-transactions
  • migration/schema files are placed into jh/db/{xxx} folders
  • support rails db:*:jh related tasks

CI jobs

  • add global.gitlab-ci.yml to override default-before_script action
  • override scripts/prepare_build.sh and util.sh to inject JH database in CI workflow
  • override three CI database yaml with JH database config

How to set up and validate locally

  1. create jh/db/migrate and jh/db/schema_migrations folders if they're not exist
  2. copy jh/config/database.yml.example contents into config/database.yml, modify it to fit your local development env
  3. run bundle exec rails db:create:jh to create JH database
  4. (optional)you can run bundle exec rails g migration CreateJHHats name:string --database jh to create a demo table migration
  5. (optional)then run bundle exec rails db:migrate:jh to perform above demo migration, it should create jh_hats table in JH database
xfyuan 编辑于

合并请求报告

加载中