Clickhouse rails
Install
- Add to Gemfile
gem 'clickhouse-rails'
- Run bundle
$ bundle install
- Init config files and folders
$ rails g clickhouse:install
- Change clickhouse.yml at
config/clickhouse.yml
path
Usage
- Create migrations
$ rails g clickhouse:migration add_tmp_table
create db/clickhouse/migrate/002_add_tmp_table.rb
- Edit file like this:
# db/clickhouse/migrate/002_add_tmp_table.rb
class AddTmpTable < Clickhouse::Rails::Migrations::Base
def self.up
create_table :tmp do |t|
t.date :date
t.uint16 :id
t.engine "MergeTree(date, (date), 8192)"
end
end
end
- Run migrations
$ rake clickhouse:db:migrate
You can create class of clickhouse table:
# app/models/custom_table.rb
class CustomTable
include Clickhouse::Table
end
And insert rows like this:
CustomTable.insert_rows([{a:1, b:2}])
CustomTable.insert_row({a:1, b:2})
Alter table migration
alter_table "analytics_table" do
fetch_column :new_ids, :uint8 # Adds column new_ids or skip it
end
TODO:
- Rollback migrations
- Alter table