From def2886ff14932fef7c5fe0ea3558fc2ae464654 Mon Sep 17 00:00:00 2001 From: nixx Date: Tue, 27 Aug 2024 15:23:10 +0300 Subject: [PATCH] fix detect model primary key for older clickhouse versions --- lib/active_record/connection_adapters/clickhouse_adapter.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/active_record/connection_adapters/clickhouse_adapter.rb b/lib/active_record/connection_adapters/clickhouse_adapter.rb index 250f4b42..fd87e88a 100644 --- a/lib/active_record/connection_adapters/clickhouse_adapter.rb +++ b/lib/active_record/connection_adapters/clickhouse_adapter.rb @@ -279,6 +279,10 @@ def column_name_for_operation(operation, node) # :nodoc: def primary_keys(table_name) structure = do_system_execute("SHOW COLUMNS FROM `#{table_name}`") structure['data'].select {|m| m[3]&.include?('PRI') }.pluck(0) + rescue ActiveRecord::ActiveRecordError => e + pk = table_structure(table_name).first + return ['id'] if pk.present? && pk[0] == 'id' + [] end def create_schema_dumper(options) # :nodoc: