Skip to content

Commit

Permalink
fix detect model primary key for older clickhouse versions
Browse files Browse the repository at this point in the history
  • Loading branch information
PNixx committed Aug 27, 2024
1 parent 205e67d commit def2886
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/active_record/connection_adapters/clickhouse_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit def2886

Please sign in to comment.