From 83675deb6d5023009f91cbae50735d19e25f75ed Mon Sep 17 00:00:00 2001 From: Daniel Westendorf Date: Mon, 18 Nov 2024 07:02:50 -0700 Subject: [PATCH] Maintain primary key type specificity (#183) --- lib/clickhouse-activerecord/schema_dumper.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/clickhouse-activerecord/schema_dumper.rb b/lib/clickhouse-activerecord/schema_dumper.rb index e2b3425..422b34b 100644 --- a/lib/clickhouse-activerecord/schema_dumper.rb +++ b/lib/clickhouse-activerecord/schema_dumper.rb @@ -109,6 +109,15 @@ def table(table, stream) end end + def column_spec_for_primary_key(column) + spec = super + + id = ActiveRecord::ConnectionAdapters::ClickhouseAdapter::NATIVE_DATABASE_TYPES.invert[{name: column.sql_type.gsub(/\(\d+\)/, "")}] + spec[:id] = id.inspect if id.present? + + spec.except!(:limit, :unsigned) # This can be removed at some date, it is only here to clean up existing schemas which have dumped these values already + end + def function(function, stream) stream.puts " # FUNCTION: #{function}" sql = @connection.show_create_function(function)