Skip to content

Commit

Permalink
fix schema dumper with low_cardinality
Browse files Browse the repository at this point in the history
  • Loading branch information
PNixx committed Jul 22, 2024
1 parent f2dbed0 commit 9dfcfb8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/clickhouse-activerecord/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,15 @@ def schema_array(column)
(column.sql_type =~ /Array?\(/).nil? ? nil : true
end

def schema_low_cardinality(column)
(column.sql_type =~ /LowCardinality?\(/).nil? ? nil : true
end

def prepare_column_options(column)
spec = {}
spec[:unsigned] = schema_unsigned(column)
spec[:array] = schema_array(column)
spec[:low_cardinality] = schema_low_cardinality(column)
spec.merge(super).compact
end

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.0.11'
VERSION = '1.0.12'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CreateSomeTable < ActiveRecord::Migration[7.1]
def change
create_table :some, id: false, options: 'MergeTree ORDER BY col' do |t|
t.string :col, null: false
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSomeTable < ActiveRecord::Migration[5.0]
class CreateSomeTable < ActiveRecord::Migration[7.1]
def up
create_table :some do

Expand Down
13 changes: 13 additions & 0 deletions spec/single/migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@
end
end

context 'without id' do
let(:directory) { 'dsl_create_view_without_id' }
it 'creates a table' do
subject

current_schema = schema(model)

expect(current_schema.keys.count).to eq(1)
expect(current_schema).to_not have_key('id')
expect(current_schema['col'].sql_type).to eq('String')
end
end

context 'with buffer table' do
let(:directory) { 'dsl_table_buffer_creation' }
it 'creates a table' do
Expand Down

0 comments on commit 9dfcfb8

Please sign in to comment.