Skip to content

Commit

Permalink
Support create table with request settings
Browse files Browse the repository at this point in the history
  • Loading branch information
PNixx committed Nov 18, 2024
1 parent 1edbaa5 commit 06020dd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- ruby: 3.2
rails: 7.1.3
- ruby: 3.2
rails: 7.2.0
rails: 7.2.1
clickhouse: [ '22.1', '24.6' ]

steps:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,13 @@ class CreateDataItems < ActiveRecord::Migration[7.1]
end
```

Create table with custom column structure:
Create table with custom column structure and codec compression:

```ruby
class CreateDataItems < ActiveRecord::Migration[7.1]
def change
create_table "data_items", id: false, options: "MergeTree PARTITION BY toYYYYMM(timestamp) ORDER BY timestamp", force: :cascade do |t|
t.integer :user_id, limit: 8, codec: 'DoubleDelta, LZ4'
t.column "timestamp", "DateTime('UTC') CODEC(DoubleDelta, LZ4)"
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/active_record/connection_adapters/clickhouse_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def create_database(name)
end
end

def create_view(table_name, **options)
def create_view(table_name, request_settings: {}, **options)
options.merge!(view: true)
options = apply_replica(table_name, options)
td = create_table_definition(apply_cluster(table_name), **options)
Expand All @@ -322,10 +322,10 @@ def create_view(table_name, **options)
drop_table(table_name, options.merge(if_exists: true))
end

do_execute(schema_creation.accept(td), format: nil)
do_execute(schema_creation.accept(td), format: nil, settings: request_settings)
end

def create_table(table_name, **options, &block)
def create_table(table_name, request_settings: {}, **options, &block)
options = apply_replica(table_name, options)
td = create_table_definition(apply_cluster(table_name), **options)
block.call td if block_given?
Expand All @@ -339,7 +339,7 @@ def create_table(table_name, **options, &block)
drop_table(table_name, options.merge(if_exists: true))
end

do_execute(schema_creation.accept(td), format: nil)
do_execute(schema_creation.accept(td), format: nil, settings: request_settings)

if options[:with_distributed]
distributed_table_name = options.delete(:with_distributed)
Expand Down
2 changes: 1 addition & 1 deletion lib/clickhouse-activerecord/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ClickhouseActiverecord
VERSION = '1.2.0'
VERSION = '1.2.1'
end

0 comments on commit 06020dd

Please sign in to comment.