clickhouse-activerecord 0.6.1.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f67a26e07ac1e077b8966dfb82626a2a4778d8060d07cedc4a93b2681a7dcfb3
4
- data.tar.gz: 2ef8add7034b493f2353a45af727646beac80a02989a8a198f2283e130cfa5be
3
+ metadata.gz: 6533de4ab9b2415a4df22e72e7ef551d4fb58c5bdc6713ec355b85dbad1174fd
4
+ data.tar.gz: 1c0a898f494c6dc7511897617ea86c2f12aa42461cf693e28e78124bde3638c6
5
5
  SHA512:
6
- metadata.gz: 9b5553336901a311c54f5ff449ada535060437dda68800acd5ee1781f6a46debde48294957dff568114657985a0475e7dc1c12bb54c6dba92f211416348d0ac4
7
- data.tar.gz: b1eb6866cd5882c545fe9bec44cc8d587edb051ec1dd259822a7a5c2ff45c21cffbfae7cc59a22bfb262544c718a69821702f663972ef4987cfd1b92cbb0a22b
6
+ metadata.gz: f6c5c2eba18dce09211cc6b8e5448aaaf2c40ca3eb5cc411aa76874ad6efc00ae257880e5997256808d02771aec7947559edfca941187c219b6724f09b9488f0
7
+ data.tar.gz: 7b7e5f520c4189b4b5a1587789d0ea2ef8b74e86c077611ac18515c45105306c6e17cfd824623ab574420beeb45d205a9f301e2db9f3befd3c3b92c4d303b978
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ['lib']
25
25
 
26
26
  spec.add_runtime_dependency 'bundler', '>= 1.13.4'
27
- spec.add_runtime_dependency 'activerecord', '>= 5.2', '< 7'
27
+ spec.add_runtime_dependency 'activerecord', '~> 7.0.0'
28
28
 
29
29
  spec.add_development_dependency 'rake', '~> 13.0'
30
30
  spec.add_development_dependency 'rspec', '~> 3.4'
@@ -60,9 +60,7 @@ module ActiveRecord
60
60
 
61
61
  def do_system_execute(sql, name = nil)
62
62
  log_with_debug(sql, "#{adapter_name} #{name}") do
63
- res = @lock.synchronize do
64
- @connection.post("/?#{@config.to_param}", "#{sql} FORMAT JSONCompact", 'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}")
65
- end
63
+ res = @connection.post("/?#{@config.to_param}", "#{sql} FORMAT JSONCompact", 'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}")
66
64
 
67
65
  process_response(res)
68
66
  end
@@ -72,9 +70,7 @@ module ActiveRecord
72
70
  log(sql, "#{adapter_name} #{name}") do
73
71
  formatted_sql = apply_format(sql, format)
74
72
  request_params = @config || {}
75
- res = @lock.synchronize do
76
- @connection.post("/?#{request_params.merge(settings).to_param}", formatted_sql, 'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}")
77
- end
73
+ res = @connection.post("/?#{request_params.merge(settings).to_param}", formatted_sql, 'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}")
78
74
 
79
75
  process_response(res)
80
76
  end
@@ -159,66 +159,73 @@ module ActiveRecord
159
159
  !native_database_types[type].nil?
160
160
  end
161
161
 
162
- def extract_limit(sql_type) # :nodoc:
163
- case sql_type
164
- when /(Nullable)?\(?String\)?/
165
- super('String')
166
- when /(Nullable)?\(?U?Int8\)?/
167
- 1
168
- when /(Nullable)?\(?U?Int16\)?/
169
- 2
170
- when /(Nullable)?\(?U?Int32\)?/
171
- nil
172
- when /(Nullable)?\(?U?Int64\)?/
173
- 8
174
- else
175
- super
162
+ class << self
163
+ def extract_limit(sql_type) # :nodoc:
164
+ case sql_type
165
+ when /(Nullable)?\(?String\)?/
166
+ super('String')
167
+ when /(Nullable)?\(?U?Int8\)?/
168
+ 1
169
+ when /(Nullable)?\(?U?Int16\)?/
170
+ 2
171
+ when /(Nullable)?\(?U?Int32\)?/
172
+ nil
173
+ when /(Nullable)?\(?U?Int64\)?/
174
+ 8
175
+ else
176
+ super
177
+ end
176
178
  end
177
- end
178
179
 
179
- # `extract_scale` and `extract_precision` are the same as in the Rails abstract base class,
180
- # except this permits a space after the comma
180
+ # `extract_scale` and `extract_precision` are the same as in the Rails abstract base class,
181
+ # except this permits a space after the comma
181
182
 
182
- def extract_scale(sql_type)
183
- case sql_type
184
- when /\((\d+)\)/ then 0
185
- when /\((\d+)(,\s?(\d+))\)/ then $3.to_i
183
+ def extract_scale(sql_type)
184
+ case sql_type
185
+ when /\((\d+)\)/ then 0
186
+ when /\((\d+)(,\s?(\d+))\)/ then $3.to_i
187
+ end
186
188
  end
187
- end
188
189
 
189
- def extract_precision(sql_type)
190
- $1.to_i if sql_type =~ /\((\d+)(,\s?\d+)?\)/
191
- end
192
-
193
- def initialize_type_map(m) # :nodoc:
194
- super
195
- register_class_with_limit m, %r(String), Type::String
196
- register_class_with_limit m, 'Date', Clickhouse::OID::Date
197
- register_class_with_precision m, %r(datetime)i, Clickhouse::OID::DateTime
198
-
199
- register_class_with_limit m, %r(Int8), Type::Integer
200
- register_class_with_limit m, %r(Int16), Type::Integer
201
- register_class_with_limit m, %r(Int32), Type::Integer
202
- register_class_with_limit m, %r(Int64), Type::Integer
203
- register_class_with_limit m, %r(Int128), Type::Integer
204
- register_class_with_limit m, %r(Int256), Type::Integer
205
-
206
- register_class_with_limit m, %r(UInt8), Type::UnsignedInteger
207
- register_class_with_limit m, %r(UInt16), Type::UnsignedInteger
208
- register_class_with_limit m, %r(UInt32), Type::UnsignedInteger
209
- register_class_with_limit m, %r(UInt64), Type::UnsignedInteger
210
- #register_class_with_limit m, %r(UInt128), Type::UnsignedInteger #not implemnted in clickhouse
211
- register_class_with_limit m, %r(UInt256), Type::UnsignedInteger
212
- # register_class_with_limit m, %r(Array), Clickhouse::OID::Array
213
- m.register_type(%r(Array)) do |sql_type|
214
- Clickhouse::OID::Array.new(sql_type)
190
+ def extract_precision(sql_type)
191
+ $1.to_i if sql_type =~ /\((\d+)(,\s?\d+)?\)/
215
192
  end
193
+
194
+ def initialize_type_map(m) # :nodoc:
195
+ super
196
+ register_class_with_limit m, %r(String), Type::String
197
+ register_class_with_limit m, 'Date', Clickhouse::OID::Date
198
+ register_class_with_precision m, %r(datetime)i, Clickhouse::OID::DateTime
199
+
200
+ register_class_with_limit m, %r(Int8), Type::Integer
201
+ register_class_with_limit m, %r(Int16), Type::Integer
202
+ register_class_with_limit m, %r(Int32), Type::Integer
203
+ register_class_with_limit m, %r(Int64), Type::Integer
204
+ register_class_with_limit m, %r(Int128), Type::Integer
205
+ register_class_with_limit m, %r(Int256), Type::Integer
206
+
207
+ register_class_with_limit m, %r(UInt8), Type::UnsignedInteger
208
+ register_class_with_limit m, %r(UInt16), Type::UnsignedInteger
209
+ register_class_with_limit m, %r(UInt32), Type::UnsignedInteger
210
+ register_class_with_limit m, %r(UInt64), Type::UnsignedInteger
211
+ #register_class_with_limit m, %r(UInt128), Type::UnsignedInteger #not implemnted in clickhouse
212
+ register_class_with_limit m, %r(UInt256), Type::UnsignedInteger
213
+ # register_class_with_limit m, %r(Array), Clickhouse::OID::Array
214
+ m.register_type(%r(Array)) do |sql_type|
215
+ Clickhouse::OID::Array.new(sql_type)
216
+ end
217
+ end
218
+ end
219
+
220
+ # In Rails 7 used constant TYPE_MAP, we need redefine method
221
+ def type_map
222
+ @type_map ||= Type::TypeMap.new.tap { |m| ClickhouseAdapter.initialize_type_map(m) }
216
223
  end
217
224
 
218
- def _quote(value)
225
+ def quote(value)
219
226
  case value
220
227
  when Array
221
- '[' + value.map { |v| _quote(v) }.join(', ') + ']'
228
+ '[' + value.map { |v| quote(v) }.join(', ') + ']'
222
229
  else
223
230
  super
224
231
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  module ClickhouseActiverecord
4
4
  class Tasks
5
-
6
5
  delegate :connection, :establish_connection, :clear_active_connections!, to: ActiveRecord::Base
7
6
 
8
7
  def initialize(configuration)
@@ -11,7 +10,7 @@ module ClickhouseActiverecord
11
10
 
12
11
  def create
13
12
  establish_master_connection
14
- connection.create_database @configuration["database"]
13
+ connection.create_database @configuration['database']
15
14
  rescue ActiveRecord::StatementInvalid => e
16
15
  if e.cause.to_s.include?('already exists')
17
16
  raise ActiveRecord::DatabaseAlreadyExists
@@ -22,7 +21,7 @@ module ClickhouseActiverecord
22
21
 
23
22
  def drop
24
23
  establish_master_connection
25
- connection.drop_database @configuration["database"]
24
+ connection.drop_database @configuration['database']
26
25
  end
27
26
 
28
27
  def purge
@@ -1,3 +1,3 @@
1
1
  module ClickhouseActiverecord
2
- VERSION = '0.6.1.1'
2
+ VERSION = '0.6.2'
3
3
  end
@@ -4,7 +4,7 @@ module CoreExtensions
4
4
  module SelectStatement
5
5
  attr_accessor :settings
6
6
 
7
- def initialize
7
+ def initialize(relation = nil)
8
8
  super
9
9
  @settings = nil
10
10
  end
@@ -1,68 +1,70 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  namespace :clickhouse do
4
-
5
4
  task prepare_schema_migration_table: :environment do
6
- ClickhouseActiverecord::SchemaMigration.create_table unless ENV['simple'] || ARGV.map{|a| a.include?('--simple') ? true : nil}.compact.any?
5
+ ClickhouseActiverecord::SchemaMigration.create_table unless ENV['simple'] || ARGV.any? { |a| a.include?('--simple') }
7
6
  end
8
7
 
9
8
  task prepare_internal_metadata_table: :environment do
10
- ClickhouseActiverecord::InternalMetadata.create_table unless ENV['simple'] || ARGV.map{|a| a.include?('--simple') ? true : nil}.compact.any?
9
+ ClickhouseActiverecord::InternalMetadata.create_table unless ENV['simple'] || ARGV.any? { |a| a.include?('--simple') }
11
10
  end
12
11
 
13
12
  task load_config: :environment do
14
- ENV['SCHEMA'] = "db/clickhouse_schema.rb"
15
- ActiveRecord::Migrator.migrations_paths = ["db/migrate_clickhouse"]
16
- ActiveRecord::Base.establish_connection(:"#{Rails.env}_clickhouse")
13
+ ENV['SCHEMA'] = 'db/clickhouse_schema.rb'
14
+ ActiveRecord::Migrator.migrations_paths = %w[db/migrate_clickhouse]
15
+ ActiveRecord::Base.establish_connection(:clickhouse)
17
16
  end
18
17
 
19
18
  namespace :schema do
20
-
21
- # todo not testing
19
+ # TODO: not testing
22
20
  desc 'Load database schema'
23
- task load: [:load_config, :prepare_internal_metadata_table] do |t, args|
24
- simple = ENV['simple'] || ARGV.map{|a| a.include?('--simple') ? true : nil}.compact.any? ? '_simple' : nil
21
+ task load: %i[load_config prepare_internal_metadata_table] do
22
+ simple = ENV['simple'] || ARGV.any? { |a| a.include?('--simple') } ? '_simple' : nil
25
23
  ClickhouseActiverecord::SchemaMigration.drop_table
26
- load("#{Rails.root}/db/clickhouse_schema#{simple}.rb")
24
+ load(Rails.root.join("db/clickhouse_schema#{simple}.rb"))
27
25
  end
28
26
 
29
27
  desc 'Dump database schema'
30
- task dump: :environment do |t, args|
31
- simple = ENV['simple'] || args[:simple] || ARGV.map{|a| a.include?('--simple') ? true : nil}.compact.any? ? '_simple' : nil
32
- filename = "#{Rails.root}/db/clickhouse_schema#{simple}.rb"
28
+ task dump: :environment do |_, args|
29
+ simple = ENV['simple'] || args[:simple] || ARGV.any? { |a| a.include?('--simple') } ? '_simple' : nil
30
+ filename = Rails.root.join("db/clickhouse_schema#{simple}.rb")
33
31
  File.open(filename, 'w:utf-8') do |file|
34
- ActiveRecord::Base.establish_connection(:"#{Rails.env}_clickhouse")
35
- ClickhouseActiverecord::SchemaDumper.dump(ActiveRecord::Base.connection, file, ActiveRecord::Base, !!simple)
32
+ ActiveRecord::Base.establish_connection(:clickhouse)
33
+ ClickhouseActiverecord::SchemaDumper.dump(ActiveRecord::Base.connection, file, ActiveRecord::Base, simple.present?)
36
34
  end
37
35
  end
38
-
39
36
  end
40
37
 
41
38
  namespace :structure do
42
39
  desc 'Load database structure'
43
40
  task load: [:load_config, 'db:check_protected_environments'] do
44
- ClickhouseActiverecord::Tasks.new(ActiveRecord::Base.configurations["#{Rails.env}_clickhouse"]).structure_load("#{Rails.root}/db/clickhouse_structure.sql")
41
+ config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
42
+ ClickhouseActiverecord::Tasks.new(config).structure_load(Rails.root.join('db/clickhouse_structure.sql'))
45
43
  end
46
44
 
47
45
  desc 'Dump database structure'
48
46
  task dump: [:load_config, 'db:check_protected_environments'] do
49
- ClickhouseActiverecord::Tasks.new(ActiveRecord::Base.configurations["#{Rails.env}_clickhouse"]).structure_dump("#{Rails.root}/db/clickhouse_structure.sql")
47
+ config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
48
+ ClickhouseActiverecord::Tasks.new(config).structure_dump(Rails.root.join('db/clickhouse_structure.sql'))
50
49
  end
51
50
  end
52
51
 
53
52
  desc 'Creates the database from DATABASE_URL or config/database.yml'
54
53
  task create: [:load_config] do
55
- ActiveRecord::Tasks::DatabaseTasks.create(ActiveRecord::Base.configurations["#{Rails.env}_clickhouse"])
54
+ config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
55
+ ActiveRecord::Tasks::DatabaseTasks.create(config)
56
56
  end
57
57
 
58
58
  desc 'Drops the database from DATABASE_URL or config/database.yml'
59
59
  task drop: [:load_config, 'db:check_protected_environments'] do
60
- ActiveRecord::Tasks::DatabaseTasks.drop(ActiveRecord::Base.configurations["#{Rails.env}_clickhouse"])
60
+ config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
61
+ ActiveRecord::Tasks::DatabaseTasks.drop(config)
61
62
  end
62
63
 
63
64
  desc 'Empty the database from DATABASE_URL or config/database.yml'
64
65
  task purge: [:load_config, 'db:check_protected_environments'] do
65
- ActiveRecord::Tasks::DatabaseTasks.purge(ActiveRecord::Base.configurations["#{Rails.env}_clickhouse"])
66
+ config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
67
+ ActiveRecord::Tasks::DatabaseTasks.purge(config)
66
68
  end
67
69
 
68
70
  # desc 'Resets your database using your migrations for the current environment'
@@ -72,7 +74,7 @@ namespace :clickhouse do
72
74
  end
73
75
 
74
76
  desc 'Migrate the clickhouse database'
75
- task migrate: [:load_config, :prepare_schema_migration_table, :prepare_internal_metadata_table] do
77
+ task migrate: %i[load_config prepare_schema_migration_table prepare_internal_metadata_table] do
76
78
  Rake::Task['db:migrate'].execute
77
79
  if File.exists? "#{Rails.root}/db/clickhouse_schema_simple.rb"
78
80
  Rake::Task['clickhouse:schema:dump'].execute(simple: true)
@@ -80,7 +82,7 @@ namespace :clickhouse do
80
82
  end
81
83
 
82
84
  desc 'Rollback the clickhouse database'
83
- task rollback: [:load_config, :prepare_schema_migration_table, :prepare_internal_metadata_table] do
85
+ task rollback: %i[load_config prepare_schema_migration_table prepare_internal_metadata_table] do
84
86
  Rake::Task['db:rollback'].execute
85
87
  end
86
88
  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.6.1.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Odintsov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-21 00:00:00.000000000 Z
11
+ date: 2023-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,22 +28,16 @@ dependencies:
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '5.2'
34
- - - "<"
31
+ - - "~>"
35
32
  - !ruby/object:Gem::Version
36
- version: '7'
33
+ version: 7.0.0
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: '5.2'
44
- - - "<"
38
+ - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '7'
40
+ version: 7.0.0
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rake
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -148,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
142
  - !ruby/object:Gem::Version
149
143
  version: '0'
150
144
  requirements: []
151
- rubygems_version: 3.3.7
145
+ rubygems_version: 3.1.6
152
146
  signing_key:
153
147
  specification_version: 4
154
148
  summary: ClickHouse ActiveRecord