Support the configuration of JH separate database
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
- Gitlab Database Schema: https://docs.gitlab.com/ee/development/database/multiple_databases.html#gitlab-schema
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 overridedefault-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
- create
jh/db/migrate
andjh/db/schema_migrations
folders if they're not exist - copy
jh/config/database.yml.example
contents intoconfig/database.yml
, modify it to fit your local development env - run
bundle exec rails db:create:jh
to create JH database - (optional)you can run
bundle exec rails g migration CreateJHHats name:string --database jh
to create a demo table migration - (optional)then run
bundle exec rails db:migrate:jh
to perform above demo migration, it should createjh_hats
table in JH database
由 xfyuan 编辑于