Skip to content

Draft: Add JH database config

张泽华请求将add-jh-database-config合并到main-jh

What does this MR do and why?

这个 MR 添加了 JH 专属的 database 的配置,需要在 jh/config/database.yml 添加数据库的配置,然后在对应的 models 中使用 connects_to database: { writing: :arunit, reading: :arunit } 这种形式设置读写的数据库。

jh/config/database.yml 中配置如下内容:

development:
  jh_database:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_jh_development
    host: /Users/zhzhang/working/gitlab-development-kit/postgresql
    port: 5432
    pool: 10
    prepared_statements: false
    variables:
      statement_timeout: 120s
    migrations_paths: ['jh/db/migrate']
    schema_migrations_path: 'jh/db/schema_migrations'

test: &test
  jh_database:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_jh_test
    host: /Users/zhzhang/working/gitlab-development-kit/postgresql
    port: 5432
    pool: 10
    prepared_statements: false
    variables:
      statement_timeout: 120s
    migrations_paths: ['jh/db/migrate']
    schema_migrations_path: 'jh/db/schema_migrations'

添加 migrations_paths 指定该数据库执行的 migration 的路径。

创建 migration 文件

执行 rails g migration CreateXXX --database jh_database 来生成 migration 文件。

执行 migration

执行 rails db:migrate 运行迁移

后续解决的问题

  • gitlab 中的数据库 ci, geo, main 都会生成各自的 rake task,(rails db:migrate:geo rails db:migrate:main rails db:migrate:ci) 没有自动生成 rails db:migrate:jh_database 任务
  • 执行完 migration 之后 schema_migrations 目录只有一条记录,是 jh_database 的记录,应该想办法让 jh_database 的 schema_migrations 放在 jh/db/schema_migrations 目录中

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

  1. 创建 jh/db/migrate 目录,创建 jh/db/schema_migrations 目录
  2. jh/config/database.yml 中 postgresql 的地址改为本机 postgresql 的 socket 地址
  3. 使用 bundle exec rails g migration CreateXXX --database jh_database 来创建数据表,migration 文件会自动创建到 jh/db/migrate 目录中
  4. 使用 bundle exec rails db:migrate 来执行迁移文件

MR acceptance checklist

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

张泽华 编辑于

合并请求报告