Skip to content

Draft: Spike JH using independent database

xfyuan请求将spike-jh-using-independent-database合并到main-jh

What does this MR do and why?

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

Use independent database for JH.

Spiked and implemented these functions:

  • JH can use a separate postgresql database
  • support such as `db:migrate:jh`, `db:rollback:jh` rake tasks now, `railt -T` will show all commands
  • generated migration/schema files is placed into `jh/db/{migrate, schema_migrations}` folder
  • JH models connect JH database successfully
  • rails handle multiple models association with joins across multiple database
  • JH tests run successfully

How to set up and validate locally

  1. create jh/db/migrate and jh/db/schema_migrations folders

  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. run `bundle exec rails db:migrate:jh` to perform 2 demo migrations, it should create `jh_cats` and `jh_balls` tables

  5. run `bundle exec rails c` enter rails console, then can try these commands:

    # model connect JH database
    JH::Cat.count
    JH::Cat.create! name: 'Ruby'
    
    # model associations with join across multiple database
    a = Project.last
    a.cats.count
    a.cats.create! name: 'Ruby'
    a.cats
    
    b = a.group
    b.cats
    
    a.cats.first.balls.create! name: 'Macbook Air'
    a.cats.first.balls
    a.balls

MR acceptance checklist

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

xfyuan 编辑于

合并请求报告

加载中