From 872a42b663890439b2df46628f875634c7fddba1 Mon Sep 17 00:00:00 2001 From: nixx Date: Mon, 2 Sep 2019 16:38:29 +0300 Subject: [PATCH] support rails 6.0 --- CHANGELOG.md | 5 ++++ clickhouse-activerecord.gemspec | 2 +- .../clickhouse/schema_statements.rb | 6 +++- .../connection_adapters/clickhouse_adapter.rb | 28 +++++++++++++++++-- lib/clickhouse-activerecord/version.rb | 2 +- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adeb9f20..080da7fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### Version 0.3.6 (Sep 2, 2019) + + * Support Rails 6.0 + * Fix relation `last` method + ### Version 0.3.4 (Jun 28, 2019) * Fix DateTime sql format without microseconds for Rails 5.2 diff --git a/clickhouse-activerecord.gemspec b/clickhouse-activerecord.gemspec index e077bd1d..c9601e73 100644 --- a/clickhouse-activerecord.gemspec +++ b/clickhouse-activerecord.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.add_runtime_dependency 'bundler', '>= 1.13.4' - spec.add_runtime_dependency 'activerecord', '~> 5.2' + spec.add_runtime_dependency 'activerecord', '>= 5.2' spec.add_development_dependency 'bundler', '~> 1.15' spec.add_development_dependency 'rake', '~> 10.0' diff --git a/lib/active_record/connection_adapters/clickhouse/schema_statements.rb b/lib/active_record/connection_adapters/clickhouse/schema_statements.rb index f1a3a35c..64898012 100644 --- a/lib/active_record/connection_adapters/clickhouse/schema_statements.rb +++ b/lib/active_record/connection_adapters/clickhouse/schema_statements.rb @@ -130,7 +130,11 @@ def new_column_from_field(table_name, field) default = field[3] default_value = extract_value_from_default(default) default_function = extract_default_function(default_value, default) - ClickhouseColumn.new(field[0], default_value, type_metadata, field[1].include?('Nullable'), table_name, default_function) + if ActiveRecord::version >= Gem::Version.new('6') + ClickhouseColumn.new(field[0], default_value, type_metadata, field[1].include?('Nullable'), default_function) + else + ClickhouseColumn.new(field[0], default_value, type_metadata, field[1].include?('Nullable'), table_name, default_function) + end end protected diff --git a/lib/active_record/connection_adapters/clickhouse_adapter.rb b/lib/active_record/connection_adapters/clickhouse_adapter.rb index 726d8ba9..739c452a 100644 --- a/lib/active_record/connection_adapters/clickhouse_adapter.rb +++ b/lib/active_record/connection_adapters/clickhouse_adapter.rb @@ -2,7 +2,6 @@ require 'clickhouse-activerecord/arel/visitors/to_sql' require 'clickhouse-activerecord/arel/table' -require 'active_record/connection_adapters/abstract_adapter' require 'active_record/connection_adapters/clickhouse/oid/date' require 'active_record/connection_adapters/clickhouse/oid/date_time' require 'active_record/connection_adapters/clickhouse/oid/big_integer' @@ -31,6 +30,21 @@ def clickhouse_connection(config) end end + module QueryMethods + + # Replace for only ClickhouseAdapter + def reverse_order! + orders = order_values.uniq + orders.reject!(&:blank?) + if self.connection.is_a?(ConnectionAdapters::ClickhouseAdapter) && orders.empty? + self.order_values = %w(date created_at).select {|c| column_names.include?(c) }.map{|c| arel_attribute(c).desc } + else + self.order_values = reverse_sql_order(orders) + end + self + end + end + module TypeCaster class Map def is_view @@ -84,7 +98,11 @@ def initialize(connection, logger, connection_parameters, config, debug = false) @config = config @debug = debug - @prepared_statements = false + if ActiveRecord::version >= Gem::Version.new('6') + @prepared_statement_status = Concurrent::ThreadLocalVar.new(false) + else + @prepared_statements = false + end connect end @@ -145,7 +163,11 @@ def quoted_date(value) end def column_name_for_operation(operation, node) # :nodoc: - column_name_from_arel_node(node) + if ActiveRecord::version >= Gem::Version.new('6') + visitor.compile(node) + else + column_name_from_arel_node(node) + end end # Executes insert +sql+ statement in the context of this connection using diff --git a/lib/clickhouse-activerecord/version.rb b/lib/clickhouse-activerecord/version.rb index 2ab1d642..89b70ce7 100644 --- a/lib/clickhouse-activerecord/version.rb +++ b/lib/clickhouse-activerecord/version.rb @@ -1,3 +1,3 @@ module ClickhouseActiverecord - VERSION = '0.3.5' + VERSION = '0.3.7' end