clickhouse-activerecord 0.4.4 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/clickhouse/schema_statements.rb +3 -1
- data/lib/active_record/connection_adapters/clickhouse_adapter.rb +6 -0
- data/lib/clickhouse-activerecord/migration.rb +2 -2
- data/lib/clickhouse-activerecord/schema_dumper.rb +24 -9
- data/lib/clickhouse-activerecord/version.rb +1 -1
- data/lib/tasks/clickhouse.rake +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64fdd9e93e5277c2639a5f88ced05132f09f1c8e455d7db2c171b8cf524295c2
|
4
|
+
data.tar.gz: f9745f682cd6a74c940dcf6e049b802e2ceefad4df10c249c0f7f47d7ac2756c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df3570664e14b336f3f6bbfa91c03a1450647e1936c45f1e61e812fd449c842be49764d3e16f2b1184bc329a7f9f2e03c6000f10e4344c132cd1f1b269e6395c
|
7
|
+
data.tar.gz: 436b4436079fe95ee5e99b3579c6b191738178540f384f6317199f4eaca99a452a178134ae2706f7fe36a121d56c458dfe215118558c5c539956804cecb85790
|
@@ -36,7 +36,7 @@ module ActiveRecord
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def table_options(table)
|
39
|
-
sql =
|
39
|
+
sql = show_create_table(table)
|
40
40
|
{ options: sql.gsub(/^(?:.*?)ENGINE = (.*?)$/, '\\1') }
|
41
41
|
end
|
42
42
|
|
@@ -156,6 +156,8 @@ module ActiveRecord
|
|
156
156
|
when "true".freeze, "false".freeze
|
157
157
|
default
|
158
158
|
# Object identifier types
|
159
|
+
when "''"
|
160
|
+
''
|
159
161
|
when /\A-?\d+\z/
|
160
162
|
$1
|
161
163
|
else
|
@@ -201,6 +201,12 @@ module ActiveRecord
|
|
201
201
|
ClickhouseActiverecord::SchemaDumper.create(self, options)
|
202
202
|
end
|
203
203
|
|
204
|
+
# @param [String] table
|
205
|
+
# @return [String]
|
206
|
+
def show_create_table(table)
|
207
|
+
do_system_execute("SHOW CREATE TABLE `#{table}`")['data'].try(:first).try(:first).gsub(/[\n\s]+/m, ' ')
|
208
|
+
end
|
209
|
+
|
204
210
|
# Create a new ClickHouse database.
|
205
211
|
def create_database(name)
|
206
212
|
sql = apply_cluster "CREATE DATABASE #{quote_table_name(name)}"
|
@@ -7,7 +7,7 @@ module ClickhouseActiverecord
|
|
7
7
|
unless table_exists?
|
8
8
|
version_options = connection.internal_string_options_for_primary_key
|
9
9
|
|
10
|
-
connection.create_table(table_name, id: false, options: 'ReplacingMergeTree(ver) PARTITION BY version ORDER BY (version)') do |t|
|
10
|
+
connection.create_table(table_name, id: false, options: 'ReplacingMergeTree(ver) PARTITION BY version ORDER BY (version)', if_not_exists: true) do |t|
|
11
11
|
t.string :version, version_options
|
12
12
|
t.column :active, 'Int8', null: false, default: '1'
|
13
13
|
t.datetime :ver, null: false, default: -> { 'now()' }
|
@@ -27,7 +27,7 @@ module ClickhouseActiverecord
|
|
27
27
|
unless table_exists?
|
28
28
|
key_options = connection.internal_string_options_for_primary_key
|
29
29
|
|
30
|
-
connection.create_table(table_name, id: false, options: 'MergeTree() PARTITION BY toDate(created_at) ORDER BY (created_at)') do |t|
|
30
|
+
connection.create_table(table_name, id: false, options: 'MergeTree() PARTITION BY toDate(created_at) ORDER BY (created_at)', if_not_exists: true) do |t|
|
31
31
|
t.string :key, key_options
|
32
32
|
t.string :value
|
33
33
|
t.timestamps
|
@@ -33,11 +33,19 @@ module ClickhouseActiverecord
|
|
33
33
|
HEADER
|
34
34
|
end
|
35
35
|
|
36
|
+
def tables(stream)
|
37
|
+
sorted_tables = @connection.tables.sort {|a,b| @connection.show_create_table(a).match(/^CREATE\s+(MATERIALIZED)\s+VIEW/) ? 1 : a <=> b }
|
38
|
+
|
39
|
+
sorted_tables.each do |table_name|
|
40
|
+
table(table_name, stream) unless ignored?(table_name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
36
44
|
def table(table, stream)
|
37
|
-
if table.match(/^\.inner
|
45
|
+
if table.match(/^\.inner/).nil?
|
38
46
|
unless simple
|
39
47
|
stream.puts " # TABLE: #{table}"
|
40
|
-
sql = @connection.
|
48
|
+
sql = @connection.show_create_table(table)
|
41
49
|
stream.puts " # SQL: #{sql.gsub(/ENGINE = Replicated(.*?)\('[^']+',\s*'[^']+',?\s?([^\)]*)?\)/, "ENGINE = \\1(\\2)")}" if sql
|
42
50
|
# super(table.gsub(/^\.inner\./, ''), stream)
|
43
51
|
|
@@ -85,13 +93,15 @@ HEADER
|
|
85
93
|
tbl.puts ", force: :cascade do |t|"
|
86
94
|
|
87
95
|
# then dump all non-primary key columns
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
96
|
+
if simple || !match
|
97
|
+
columns.each do |column|
|
98
|
+
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type)
|
99
|
+
next if column.name == pk
|
100
|
+
type, colspec = column_spec(column)
|
101
|
+
tbl.print " t.#{type} #{column.name.inspect}"
|
102
|
+
tbl.print ", #{format_colspec(colspec)}" if colspec.present?
|
103
|
+
tbl.puts
|
104
|
+
end
|
95
105
|
end
|
96
106
|
|
97
107
|
indexes_in_create(table, tbl)
|
@@ -123,5 +133,10 @@ HEADER
|
|
123
133
|
super
|
124
134
|
end
|
125
135
|
end
|
136
|
+
|
137
|
+
def schema_limit(column)
|
138
|
+
return nil if column.type == :float
|
139
|
+
super
|
140
|
+
end
|
126
141
|
end
|
127
142
|
end
|
data/lib/tasks/clickhouse.rake
CHANGED
@@ -20,8 +20,9 @@ namespace :clickhouse do
|
|
20
20
|
|
21
21
|
# todo not testing
|
22
22
|
desc 'Load database schema'
|
23
|
-
task load: [:load_config, :
|
23
|
+
task load: [:load_config, :prepare_internal_metadata_table] do |t, args|
|
24
24
|
simple = ENV['simple'] || ARGV.map{|a| a.include?('--simple') ? true : nil}.compact.any? ? '_simple' : nil
|
25
|
+
ClickhouseActiverecord::SchemaMigration.drop_table
|
25
26
|
load("#{Rails.root}/db/clickhouse_schema#{simple}.rb")
|
26
27
|
end
|
27
28
|
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Odintsov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
- !ruby/object:Gem::Version
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
|
-
rubygems_version: 3.0.
|
152
|
+
rubygems_version: 3.0.3
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: ClickHouse ActiveRecord
|