Skip to content

Commit 2352ac5

Browse files
committed
fix schema dump ignoring indexes with multi-column expressions
1 parent 48c74a6 commit 2352ac5

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

lib/clickhouse-activerecord/schema_dumper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def table(table, stream)
9999
end
100100
end
101101

102-
indexes = sql.scan(/INDEX \S+ \S+ TYPE .*? GRANULARITY \d+/)
102+
indexes = sql.scan(/INDEX \S+ .+? TYPE .*? GRANULARITY \d+/)
103103
if indexes.any?
104104
tbl.puts ''
105105
indexes.flatten.map!(&:strip).each do |index|
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class CreateSimpleIndex < ActiveRecord::Migration[7.1]
4+
def up
5+
add_index :some, 'date', name: 'simple_idx', type: 'minmax', granularity: 1
6+
end
7+
end

spec/single/migration_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,25 @@
311311

312312
ActiveRecord::Base.connection.clear_index('some', 'idx2')
313313
end
314+
315+
it 'dumps indexes' do
316+
require 'clickhouse-activerecord/schema_dumper'
317+
318+
quietly { migration_context.up(1) }
319+
320+
current_schema = StringIO.new
321+
ClickhouseActiverecord::SchemaDumper.dump(ActiveRecord::Base.connection, current_schema)
322+
323+
expect(current_schema.string).to include('t.index "(int1 * int2, date)", name: "idx", type: "minmax", granularity: 3')
324+
325+
quietly { migration_context.up(4) }
326+
327+
current_schema = StringIO.new
328+
ClickhouseActiverecord::SchemaDumper.dump(ActiveRecord::Base.connection, current_schema)
329+
330+
expect(current_schema.string).to include('t.index "int1 * int2", name: "idx2", type: "set(10)", granularity: 4')
331+
expect(current_schema.string).to include('t.index "date", name: "simple_idx", type: "minmax", granularity: 1')
332+
end
314333
end
315334
end
316335
end

0 commit comments

Comments
 (0)