clickhouse-activerecord 1.0.11 → 1.0.13

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: 48c4995d403717ca5d9b4d8bdadbedd4bae8d42cf7dad7f37768d12922ebb032
4
- data.tar.gz: 01cc522bc62fc1015e66b9239b11bf0e5cf4fa9bc998375e0021130737cacaf3
3
+ metadata.gz: 71882da78e208681ad3f28c05bfad0ca4746f8e6b046a4b8cd14c2fa26a007b6
4
+ data.tar.gz: b0daa57171963e98a6d0aa4284b7728731009960a07cbdd45a0cc104fcb14213
5
5
  SHA512:
6
- metadata.gz: 8ee641fb865778a883b93d56a834ab4c842e3f0531a60c3e6a10278a558b9eddc14a101a2dd96688c983090d5dabfb1d3040f78ff09946facc7f7709cbd81dec
7
- data.tar.gz: 147bcb2f4c7af96e9d68532de7f0c16f4fda78ac31c63735d12f7f7e04597869d827c7fd58cf72e8adc9750395d12442d6becbcc2d9e534e9819e6eef839f20a
6
+ metadata.gz: aea7e2146f23b6183e4583a1b5cc7e4a38131fabff83574415a1e6c8bd607089305265c53ddb54dcbe2c476144d21b4b97795123cd7bfa038ef7a975de7bde9d
7
+ data.tar.gz: 2228a7f2a7e71005f2d2bb910c721373671bdbb7a6ea15e370ecd923a8fb47fa7cebaa548b50ed7ca9bf8d6d6c2ac27a95cca8c680604ba95934866b6488a8b9
data/README.md CHANGED
@@ -149,7 +149,15 @@ Structure load from `db/clickhouse_structure.sql` file:
149
149
  $ rake db:schema:dump
150
150
  $ rake db:schema:load
151
151
  $ rake db:structure:dump
152
- $ rake db:structure:load
152
+ $ rake db:structure:load
153
+
154
+ ### RSpec
155
+
156
+ For auto truncate tables before each test add to `spec/rails_helper.rb` file:
157
+
158
+ ```
159
+ require 'clickhouse-activerecord/rspec'
160
+ ```
153
161
 
154
162
  ### Insert and select data
155
163
 
@@ -133,6 +133,16 @@ module ActiveRecord
133
133
  connect
134
134
  end
135
135
 
136
+ # Savepoints are not supported, noop
137
+ def create_savepoint(name)
138
+ end
139
+
140
+ def exec_rollback_to_savepoint(name)
141
+ end
142
+
143
+ def release_savepoint(name)
144
+ end
145
+
136
146
  def migrations_paths
137
147
  @config[:migrations_paths] || 'db/migrate_clickhouse'
138
148
  end
@@ -264,7 +274,7 @@ module ActiveRecord
264
274
  # @param [String] table
265
275
  # @return [String]
266
276
  def show_create_table(table)
267
- do_system_execute("SHOW CREATE TABLE `#{table}`")['data'].try(:first).try(:first).gsub(/[\n\s]+/m, ' ')
277
+ do_system_execute("SHOW CREATE TABLE `#{table}`")['data'].try(:first).try(:first).gsub(/[\n\s]+/m, ' ').gsub("#{@config[:database]}.", "")
268
278
  end
269
279
 
270
280
  # Create a new ClickHouse database.
@@ -16,8 +16,12 @@ module Arel
16
16
  # https://clickhouse.com/docs/en/sql-reference/statements/delete
17
17
  # DELETE and UPDATE in ClickHouse working only without table name
18
18
  def visit_Arel_Attributes_Attribute(o, collector)
19
- collector << quote_table_name(o.relation.table_alias || o.relation.name) << '.' unless collector.value.start_with?('DELETE FROM ') || collector.value.include?(' UPDATE ')
20
- collector << quote_column_name(o.name)
19
+ if collector.value.is_a?(String)
20
+ collector << quote_table_name(o.relation.table_alias || o.relation.name) << '.' unless collector.value.start_with?('DELETE FROM ') || collector.value.include?(' UPDATE ')
21
+ collector << quote_column_name(o.name)
22
+ else
23
+ super
24
+ end
21
25
  end
22
26
 
23
27
  def visit_Arel_Nodes_SelectOptions(o, collector)
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.configure do |config|
4
+ config.before do
5
+ ActiveRecord::Base.configurations.configurations.select { |x| x.env_name == Rails.env && x.adapter == 'clickhouse' }.each do |config|
6
+ ActiveRecord::Base.establish_connection(config)
7
+ ActiveRecord::Base.connection.tables.each do |table|
8
+ ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{table}")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -168,10 +168,15 @@ HEADER
168
168
  (column.sql_type =~ /Array?\(/).nil? ? nil : true
169
169
  end
170
170
 
171
+ def schema_low_cardinality(column)
172
+ (column.sql_type =~ /LowCardinality?\(/).nil? ? nil : true
173
+ end
174
+
171
175
  def prepare_column_options(column)
172
176
  spec = {}
173
177
  spec[:unsigned] = schema_unsigned(column)
174
178
  spec[:array] = schema_array(column)
179
+ spec[:low_cardinality] = schema_low_cardinality(column)
175
180
  spec.merge(super).compact
176
181
  end
177
182
 
@@ -1,3 +1,3 @@
1
1
  module ClickhouseActiverecord
2
- VERSION = '1.0.11'
2
+ VERSION = '1.0.13'
3
3
  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: 1.0.11
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Odintsov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-19 00:00:00.000000000 Z
11
+ date: 2024-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -121,6 +121,7 @@ files:
121
121
  - lib/arel/visitors/clickhouse.rb
122
122
  - lib/clickhouse-activerecord.rb
123
123
  - lib/clickhouse-activerecord/railtie.rb
124
+ - lib/clickhouse-activerecord/rspec.rb
124
125
  - lib/clickhouse-activerecord/schema.rb
125
126
  - lib/clickhouse-activerecord/schema_dumper.rb
126
127
  - lib/clickhouse-activerecord/tasks.rb