clickhouse-activerecord 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/lib/active_record/connection_adapters/clickhouse/schema_creation.rb +23 -2
- data/lib/active_record/connection_adapters/clickhouse/schema_definitions.rb +1 -1
- data/lib/active_record/connection_adapters/clickhouse_adapter.rb +24 -3
- data/lib/clickhouse-activerecord/schema_dumper.rb +1 -1
- data/lib/clickhouse-activerecord/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cf76e043406ab83146104d257da665657dc9905b6517ea02956f9034ae52ebf
|
4
|
+
data.tar.gz: 21da146747adec65a6e61bd09dc1ded2be7fd025ecea23736d0985708bafa70b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bee84efbe4e210107575a1121a4adc8df4da2f85349abfec2f27c964917a7655438b01cceed36d83fe49f2f70e8f0d8ba32f7e92bb26b5ac5beceddf5243e626
|
7
|
+
data.tar.gz: bb1576674cbec042f2f2d949a6e35e8ce4ce22615a0bb0aac2d0ee56b35e200cdb28d72a31010e1143c95b47d397821568e709aa6fdd3c0ee9f8f76605de356c
|
data/CHANGELOG.md
CHANGED
@@ -6,15 +6,17 @@ module ActiveRecord
|
|
6
6
|
class SchemaCreation < AbstractAdapter::SchemaCreation# :nodoc:
|
7
7
|
|
8
8
|
def visit_AddColumnDefinition(o)
|
9
|
-
+"ADD COLUMN #{accept(o.column)}"
|
9
|
+
sql = +"ADD COLUMN #{accept(o.column)}"
|
10
|
+
sql << " AFTER " + quote_column_name(o.column.options[:after]) if o.column.options.key?(:after)
|
11
|
+
sql
|
10
12
|
end
|
11
13
|
|
12
14
|
def add_column_options!(sql, options)
|
13
|
-
sql << " DEFAULT #{quote_default_expression(options[:default], options[:column])}" if options_include_default?(options)
|
14
15
|
if options[:null] || options[:null].nil?
|
15
16
|
sql.gsub!(/\s+(.*)/, ' Nullable(\1)')
|
16
17
|
end
|
17
18
|
sql.gsub!(/(\sString)\(\d+\)/, '\1')
|
19
|
+
sql << " DEFAULT #{quote_default_expression(options[:default], options[:column])}" if options_include_default?(options)
|
18
20
|
sql
|
19
21
|
end
|
20
22
|
|
@@ -47,6 +49,25 @@ module ActiveRecord
|
|
47
49
|
" TEMPORARY" if o.temporary
|
48
50
|
" MATERIALIZED" if o.materialized
|
49
51
|
end
|
52
|
+
|
53
|
+
def visit_ChangeColumnDefinition(o)
|
54
|
+
column = o.column
|
55
|
+
column.sql_type = type_to_sql(column.type, column.options)
|
56
|
+
options = column_options(column)
|
57
|
+
|
58
|
+
quoted_column_name = quote_column_name(o.name)
|
59
|
+
type = column.sql_type
|
60
|
+
type = "Nullable(#{type})" if options[:null]
|
61
|
+
change_column_sql = +"MODIFY COLUMN #{quoted_column_name} #{type}"
|
62
|
+
|
63
|
+
if options.key?(:default)
|
64
|
+
quoted_default = quote_default_expression(options[:default], column)
|
65
|
+
change_column_sql << " DEFAULT #{quoted_default}"
|
66
|
+
end
|
67
|
+
|
68
|
+
change_column_sql
|
69
|
+
end
|
70
|
+
|
50
71
|
end
|
51
72
|
end
|
52
73
|
end
|
@@ -205,7 +205,7 @@ module ActiveRecord
|
|
205
205
|
def create_database(name)
|
206
206
|
sql = apply_cluster "CREATE DATABASE #{quote_table_name(name)}"
|
207
207
|
log_with_debug(sql, adapter_name) do
|
208
|
-
res = @connection.post("/?#{@config.except(:database).to_param}",
|
208
|
+
res = @connection.post("/?#{@config.except(:database).to_param}", sql)
|
209
209
|
process_response(res)
|
210
210
|
end
|
211
211
|
end
|
@@ -213,7 +213,7 @@ module ActiveRecord
|
|
213
213
|
def create_view(table_name, **options)
|
214
214
|
options.merge!(view: true)
|
215
215
|
options = apply_replica(table_name, options)
|
216
|
-
td = create_table_definition(table_name, options)
|
216
|
+
td = create_table_definition(apply_cluster(table_name), options)
|
217
217
|
yield td if block_given?
|
218
218
|
|
219
219
|
if options[:force]
|
@@ -225,7 +225,7 @@ module ActiveRecord
|
|
225
225
|
|
226
226
|
def create_table(table_name, **options)
|
227
227
|
options = apply_replica(table_name, options)
|
228
|
-
td = create_table_definition(table_name, options)
|
228
|
+
td = create_table_definition(apply_cluster(table_name), options)
|
229
229
|
yield td if block_given?
|
230
230
|
|
231
231
|
if options[:force]
|
@@ -252,6 +252,21 @@ module ActiveRecord
|
|
252
252
|
do_execute apply_cluster "DROP TABLE#{' IF EXISTS' if options[:if_exists]} #{quote_table_name(table_name)}"
|
253
253
|
end
|
254
254
|
|
255
|
+
def change_column(table_name, column_name, type, options = {})
|
256
|
+
result = do_execute "ALTER TABLE #{quote_table_name(table_name)} #{change_column_for_alter(table_name, column_name, type, options)}"
|
257
|
+
raise "Error parse json response: #{result}" if result.presence && !result.is_a?(Hash)
|
258
|
+
end
|
259
|
+
|
260
|
+
def change_column_null(table_name, column_name, null, default = nil)
|
261
|
+
structure = table_structure(table_name).select{|v| v[0] == column_name.to_s}.first
|
262
|
+
raise "Column #{column_name} not found in table #{table_name}" if structure.nil?
|
263
|
+
change_column table_name, column_name, structure[1].gsub(/(Nullable\()?(.*?)\)?/, '\2'), {null: null, default: default}.compact
|
264
|
+
end
|
265
|
+
|
266
|
+
def change_column_default(table_name, column_name, default)
|
267
|
+
change_column table_name, column_name, nil, {default: default}.compact
|
268
|
+
end
|
269
|
+
|
255
270
|
def cluster
|
256
271
|
@full_config[:cluster_name]
|
257
272
|
end
|
@@ -274,6 +289,12 @@ module ActiveRecord
|
|
274
289
|
result
|
275
290
|
end
|
276
291
|
|
292
|
+
def change_column_for_alter(table_name, column_name, type, options = {})
|
293
|
+
td = create_table_definition(table_name)
|
294
|
+
cd = td.new_column_definition(column_name, type, options)
|
295
|
+
schema_creation.accept(ChangeColumnDefinition.new(cd, column_name))
|
296
|
+
end
|
297
|
+
|
277
298
|
private
|
278
299
|
|
279
300
|
def connect
|
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.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Odintsov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|