clickhouse-activerecord 0.5.13 → 0.5.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0d11fee214ec195a5ccb8569e2f0302c7273a74bacc012069837a7f5fd5bec6
4
- data.tar.gz: 32d98a8051a6246d567d5ef9278b4a6795b385d4290203c6d6742c961a6490d3
3
+ metadata.gz: 4ff54c1e4a5da2543e1a64ad8002822bf82ba5d3b6f7f74f00f1cb0ce23679dd
4
+ data.tar.gz: 61158e185f4617e88701d2a9b1d261ddf7b4f9c7617454e66a899d55900a34a8
5
5
  SHA512:
6
- metadata.gz: 0bfb1e29754b50d7c33033dd0be37d1a4205dbb9ff12671fc27f217572d493f2a01c3a28c98e0bfaa968564ca8f714c5abefecf6d14638fa4f767aa00ea13fdf
7
- data.tar.gz: eebb37d468dbf8695b50b60ee47e3641517778ee06dc82df767e126bc8f7cd94e9de8c690622777c849ba0ce8adec65d9ff55d30ea0a0b25981f6e41afcbe1dd
6
+ metadata.gz: 2d690a0cf443ce6e1b3f90e0443263e27b44be546fd080c11c8aa0278d6f630360371057880e667d4f5f76e31ac9bccf1b71fdfffeda09aa7d4d9a49af786f79
7
+ data.tar.gz: f0f96caa0371b8206cee957e38b9f24993549eaa2dcc03265d4b398e051a0a9ebe32a7262c949bf4510dda3f843d8e9e2bb2437cc364dd9bf06f5a622e085530
@@ -48,19 +48,6 @@ module ActiveRecord
48
48
  end
49
49
  end
50
50
 
51
- module ClickhouseRelationReverseOrder
52
- def reverse_order!
53
- return super unless connection.is_a?(ConnectionAdapters::ClickhouseAdapter)
54
-
55
- orders = order_values.uniq.compact_blank
56
- return super unless orders.empty? && !primary_key
57
-
58
- self.order_values = %w(date created_at).select {|c| column_names.include?(c) }.map{|c| arel_attribute(c).desc }
59
- self
60
- end
61
- end
62
- Relation.prepend(ClickhouseRelationReverseOrder)
63
-
64
51
  module TypeCaster
65
52
  class Map
66
53
  def is_view
@@ -74,7 +61,7 @@ module ActiveRecord
74
61
  end
75
62
 
76
63
  module ModelSchema
77
- module ClassMethods
64
+ module ClassMethods
78
65
  def is_view
79
66
  @is_view || false
80
67
  end
@@ -352,8 +339,22 @@ module ActiveRecord
352
339
  end
353
340
  end
354
341
 
342
+ def add_column(table_name, column_name, type, **options)
343
+ return if options[:if_not_exists] == true && column_exists?(table_name, column_name, type)
344
+
345
+ at = create_alter_table table_name
346
+ at.add_column(column_name, type, **options)
347
+ execute(schema_creation.accept(at), nil, settings: {wait_end_of_query: 1, send_progress_in_http_headers: 1})
348
+ end
349
+
350
+ def remove_column(table_name, column_name, type = nil, **options)
351
+ return if options[:if_exists] == true && !column_exists?(table_name, column_name)
352
+
353
+ execute("ALTER TABLE #{quote_table_name(table_name)} #{remove_column_for_alter(table_name, column_name, type, **options)}", nil, settings: {wait_end_of_query: 1, send_progress_in_http_headers: 1})
354
+ end
355
+
355
356
  def change_column(table_name, column_name, type, options = {})
356
- result = do_execute "ALTER TABLE #{quote_table_name(table_name)} #{change_column_for_alter(table_name, column_name, type, options)}"
357
+ result = do_execute("ALTER TABLE #{quote_table_name(table_name)} #{change_column_for_alter(table_name, column_name, type, options)}", nil, settings: {wait_end_of_query: 1, send_progress_in_http_headers: 1})
357
358
  raise "Error parse json response: #{result}" if result.presence && !result.is_a?(Hash)
358
359
  end
359
360
 
@@ -4,6 +4,12 @@ module ClickhouseActiverecord
4
4
  require 'rails'
5
5
 
6
6
  class Railtie < Rails::Railtie
7
+ initializer "clickhouse.load" do
8
+ ActiveSupport.on_load :active_record do
9
+ ClickhouseActiverecord.load
10
+ end
11
+ end
12
+
7
13
  rake_tasks { load 'tasks/clickhouse.rake' }
8
14
  end
9
15
  end
@@ -1,3 +1,3 @@
1
1
  module ClickhouseActiverecord
2
- VERSION = '0.5.13'
2
+ VERSION = '0.5.14'
3
3
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'active_record/connection_adapters/clickhouse_adapter'
4
4
 
5
+ require 'core_extensions/active_record/relation'
6
+
5
7
  require_relative '../core_extensions/active_record/migration/command_recorder'
6
8
  ActiveRecord::Migration::CommandRecorder.include CoreExtensions::ActiveRecord::Migration::CommandRecorder
7
9
 
@@ -14,5 +16,7 @@ if defined?(Rails::Railtie)
14
16
  end
15
17
 
16
18
  module ClickhouseActiverecord
17
-
19
+ def self.load
20
+ ActiveRecord::Relation.prepend(CoreExtensions::ActiveRecord::Relation)
21
+ end
18
22
  end
@@ -0,0 +1,15 @@
1
+ module CoreExtensions
2
+ module ActiveRecord
3
+ module Relation
4
+ def reverse_order!
5
+ return super unless connection.is_a?(::ActiveRecord::ConnectionAdapters::ClickhouseAdapter)
6
+
7
+ orders = order_values.uniq.reject(&:blank?)
8
+ return super unless orders.empty? && !primary_key
9
+
10
+ self.order_values = (column_names & %w[date created_at]).map { |c| arel_table[c].desc }
11
+ self
12
+ end
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clickhouse-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.13
4
+ version: 0.5.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Odintsov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-20 00:00:00.000000000 Z
11
+ date: 2023-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,6 +130,7 @@ files:
130
130
  - lib/clickhouse-activerecord/schema_dumper.rb
131
131
  - lib/clickhouse-activerecord/tasks.rb
132
132
  - lib/clickhouse-activerecord/version.rb
133
+ - lib/core_extensions/active_record/relation.rb
133
134
  - lib/generators/clickhouse_migration_generator.rb
134
135
  - lib/tasks/clickhouse.rake
135
136
  homepage: https://github.com/pnixx/clickhouse-activerecord