Skip to content
代码片段 群组 项目
未验证 提交 3e635345 编辑于 作者: Vladimir Shushlin's avatar Vladimir Shushlin 提交者: GitLab
浏览文件

Update ClickHouse dev docs on migrations

上级 a72732b4
No related branches found
No related tags found
无相关合并请求
......@@ -45,8 +45,23 @@ ClickHouse::Client.select('SELECT 1', :main)
## Database schema and migrations
There are `bundle exec rake gitlab:clickhouse:migrate` and `bundle exec rake gitlab:clickhouse:rollback` tasks
(introduced in [!136103](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/136103)).
To run database migrations, execute:
```shell
bundle exec rake gitlab:clickhouse:migrate
```
To rollback last N migrations, execute:
```shell
bundle exec rake gitlab:clickhouse:rollback:main STEP=N
```
Or use the following command to rollback all migrations:
```shell
bundle exec rake gitlab:clickhouse:rollback:main VERSION=0
```
You can create a migration by creating a Ruby migration file in `db/click_house/migrate` folder. It should be prefixed with a timestamp in the format `YYYYMMDDHHMMSS_description_of_migration.rb`
......@@ -75,17 +90,6 @@ class CreateIssues < ClickHouse::Migration
end
```
When you're working locally in your development environment, you can create or re-create your table schema by
executing `rake gitlab:clickhouse:rollback` and `rake gitlab:clickhouse:migrate`.
Alternatively, you can use the following snippet in the Rails console:
```ruby
require_relative 'spec/support/database/click_house/hooks.rb'
# Drops and re-creates all tables
ClickHouseTestRunner.new.ensure_schema
```
## Writing database queries
For the ClickHouse database we don't use ORM (Object Relational Mapping). The main reason is that the GitLab application has many customizations for the `ActiveRecord` PostgresSQL adapter and the application generally assumes that all databases are using `PostgreSQL`. Since ClickHouse-related features are still in a very early stage of development, we decided to implement a simple HTTP client to avoid hard to discover bugs and long debugging time when dealing with multiple `ActiveRecord` adapters.
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册