clickhouse-activerecord 0.3.4 → 0.3.12
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 +4 -4
- data/CHANGELOG.md +18 -2
- data/README.md +61 -10
- data/clickhouse-activerecord.gemspec +2 -2
- data/lib/active_record/connection_adapters/clickhouse/oid/date_time.rb +1 -0
- data/lib/active_record/connection_adapters/clickhouse/schema_statements.rb +23 -41
- data/lib/active_record/connection_adapters/clickhouse_adapter.rb +60 -7
- data/lib/clickhouse-activerecord/arel/table.rb +9 -0
- data/lib/clickhouse-activerecord/arel/visitors/to_sql.rb +4 -5
- data/lib/clickhouse-activerecord/tasks.rb +15 -1
- data/lib/clickhouse-activerecord/version.rb +1 -1
- data/lib/generators/clickhouse_migration_generator.rb +15 -1
- data/lib/tasks/clickhouse.rake +12 -0
- metadata +5 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50dff8ae7219e2f3a04ee530331d19ca0b61396437723819891c1d8b41f0692d
|
4
|
+
data.tar.gz: 75d50e8e2f32fa84f990bc15da6177082b7a0b0d5a508cba822b3c3afbc60c41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebdeb04ba96eb81eb76efdbd09580b51719656136de38b973cea267bc1405dba03cd417058df1909b9bd1e4279c97d845292947de251792f94fc9f0b30cf65cb
|
7
|
+
data.tar.gz: 3a0b0feda885ab74f54f6d61b78ff02efed20d403b0bc4bff99b83ee811d4988e8620c92a84e549bc70e0ccb93c662e665a562bb51d49b5ed552bc850c076696
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,26 @@
|
|
1
|
+
### Version 0.3.10 (Dec 20, 2019)
|
2
|
+
|
3
|
+
* Support structure dump/load [@StoneGod](https://github.com/StoneGod)
|
4
|
+
|
5
|
+
### Version 0.3.6 (Sep 2, 2019)
|
6
|
+
|
7
|
+
* Support Rails 6.0
|
8
|
+
* Fix relation `last` method
|
9
|
+
|
10
|
+
### Version 0.3.4 (Jun 28, 2019)
|
11
|
+
|
12
|
+
* Fix DateTime sql format without microseconds for Rails 5.2
|
13
|
+
* Support ssl connection
|
14
|
+
* Migration support
|
15
|
+
* Rake tasks for create / drop database
|
16
|
+
|
1
17
|
### Version 0.3.0 (Nov 27, 2018)
|
2
18
|
|
3
19
|
* Support materialized view
|
4
20
|
* Aggregated functions for view
|
5
21
|
* Schema dumper with SQL create table
|
6
22
|
* Added migrations support [@Bugagazavr](https://github.com/Bugagazavr)
|
7
|
-
|
23
|
+
|
8
24
|
### Version 0.2.0 (Oct 3, 2017)
|
9
25
|
|
10
26
|
* Support Rails 5.0
|
@@ -12,7 +28,7 @@
|
|
12
28
|
### Version 0.1.2 (Sep 27, 2017)
|
13
29
|
|
14
30
|
* Fix Big Int type
|
15
|
-
|
31
|
+
|
16
32
|
### Version 0.1.0 (Aug 31, 2017)
|
17
33
|
|
18
34
|
* Initial release
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Clickhouse::Activerecord
|
2
2
|
|
3
3
|
A Ruby database ActiveRecord driver for ClickHouse. Support Rails >= 5.2.
|
4
|
+
Tested on ClickHouse version 18.14.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -17,8 +18,22 @@ And then execute:
|
|
17
18
|
Or install it yourself as:
|
18
19
|
|
19
20
|
$ gem install clickhouse-activerecord
|
21
|
+
|
22
|
+
## Available database connection parameters
|
23
|
+
```yml
|
24
|
+
default: &default
|
25
|
+
adapter: clickhouse
|
26
|
+
database: database
|
27
|
+
host: localhost
|
28
|
+
port: 8123
|
29
|
+
username: username
|
30
|
+
password: password
|
31
|
+
ssl: true # optional for using ssl connection
|
32
|
+
debug: true # use for showing in to log technical information
|
33
|
+
migrations_paths: db/clickhouse # optional, default: db/migrate_clickhouse
|
34
|
+
```
|
20
35
|
|
21
|
-
## Usage
|
36
|
+
## Usage in Rails 5
|
22
37
|
|
23
38
|
Add your `database.yml` connection information with postfix `_clickhouse` for you environment:
|
24
39
|
|
@@ -26,10 +41,6 @@ Add your `database.yml` connection information with postfix `_clickhouse` for yo
|
|
26
41
|
development_clickhouse:
|
27
42
|
adapter: clickhouse
|
28
43
|
database: database
|
29
|
-
host: localhost
|
30
|
-
username: username
|
31
|
-
password: password
|
32
|
-
debug: true # use for showing in to log technical information
|
33
44
|
```
|
34
45
|
|
35
46
|
Add to your model:
|
@@ -54,13 +65,34 @@ Or global connection:
|
|
54
65
|
development:
|
55
66
|
adapter: clickhouse
|
56
67
|
database: database
|
57
|
-
|
58
|
-
|
59
|
-
|
68
|
+
```
|
69
|
+
|
70
|
+
## Usage in Rails 6 with second database
|
71
|
+
|
72
|
+
Add your `database.yml` connection information for you environment:
|
73
|
+
|
74
|
+
```yml
|
75
|
+
development:
|
76
|
+
primary:
|
77
|
+
...
|
78
|
+
|
79
|
+
clickhouse:
|
80
|
+
adapter: clickhouse
|
81
|
+
database: database
|
82
|
+
```
|
83
|
+
|
84
|
+
Connection [Multiple Databases with Active Record](https://guides.rubyonrails.org/active_record_multiple_databases.html) or short example:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
class Action < ActiveRecord::Base
|
88
|
+
connects_to database: { writing: :clickhouse, reading: :clickhouse }
|
89
|
+
end
|
60
90
|
```
|
61
91
|
|
62
92
|
### Rake tasks
|
63
93
|
|
94
|
+
**Note!** For Rails 6 you can use default rake tasks if you configure `migrations_paths` in your `database.yml`, for example: `rake db:migrate`
|
95
|
+
|
64
96
|
Create / drop / purge / reset database:
|
65
97
|
|
66
98
|
$ rake clickhouse:create
|
@@ -75,6 +107,10 @@ Migration:
|
|
75
107
|
|
76
108
|
Rollback migration not supported!
|
77
109
|
|
110
|
+
### Dump / Load for multiple using databases
|
111
|
+
|
112
|
+
If you using multiple databases, for example: PostgreSQL, Clickhouse.
|
113
|
+
|
78
114
|
Schema dump to `db/clickhouse_schema.rb` file:
|
79
115
|
|
80
116
|
$ rake clickhouse:schema:dump
|
@@ -82,9 +118,24 @@ Schema dump to `db/clickhouse_schema.rb` file:
|
|
82
118
|
Schema load from `db/clickhouse_schema.rb` file:
|
83
119
|
|
84
120
|
$ rake clickhouse:schema:load
|
85
|
-
|
121
|
+
|
86
122
|
We use schema for emulate development or tests environment on PostgreSQL adapter.
|
87
123
|
|
124
|
+
Structure dump to `db/clickhouse_structure.sql` file:
|
125
|
+
|
126
|
+
$ rake clickhouse:structure:dump
|
127
|
+
|
128
|
+
Structure load from `db/clickhouse_structure.sql` file:
|
129
|
+
|
130
|
+
$ rake clickhouse:structure:load
|
131
|
+
|
132
|
+
### Dump / Load for only Clickhouse database using
|
133
|
+
|
134
|
+
$ rake db:schema:dump
|
135
|
+
$ rake db:schema:load
|
136
|
+
$ rake db:structure:dump
|
137
|
+
$ rake db:structure:load
|
138
|
+
|
88
139
|
### Insert and select data
|
89
140
|
|
90
141
|
```ruby
|
@@ -105,7 +156,7 @@ ActionView.maximum(:date)
|
|
105
156
|
|
106
157
|
Donations to this project are going directly to [PNixx](https://github.com/PNixx), the original author of this project:
|
107
158
|
|
108
|
-
* BTC address: `
|
159
|
+
* BTC address: `1H3rhpf7WEF5JmMZ3PVFMQc7Hm29THgUfN`
|
109
160
|
* ETH address: `0x6F094365A70fe7836A633d2eE80A1FA9758234d5`
|
110
161
|
* XMR address: `42gP71qLB5M43RuDnrQ3vSJFFxis9Kw9VMURhpx9NLQRRwNvaZRjm2TFojAMC8Fk1BQhZNKyWhoyJSn5Ak9kppgZPjE17Zh`
|
111
162
|
|
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ['lib']
|
25
25
|
|
26
|
-
spec.add_runtime_dependency 'bundler', '
|
27
|
-
spec.add_runtime_dependency 'activerecord', '
|
26
|
+
spec.add_runtime_dependency 'bundler', '>= 1.13.4'
|
27
|
+
spec.add_runtime_dependency 'activerecord', '>= 5.2'
|
28
28
|
|
29
29
|
spec.add_development_dependency 'bundler', '~> 1.15'
|
30
30
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -17,6 +17,8 @@ module ActiveRecord
|
|
17
17
|
def exec_query(sql, name = nil, binds = [], prepare: false)
|
18
18
|
result = do_execute(sql, name)
|
19
19
|
ActiveRecord::Result.new(result['meta'].map { |m| m['name'] }, result['data'])
|
20
|
+
rescue StandartError => _e
|
21
|
+
raise ActiveRecord::ActiveRecordError, "Response: #{result}"
|
20
22
|
end
|
21
23
|
|
22
24
|
def exec_update(_sql, _name = nil, _binds = [])
|
@@ -38,37 +40,6 @@ module ActiveRecord
|
|
38
40
|
{ options: sql.gsub(/^(?:.*?)ENGINE = (.*?)$/, '\\1') }
|
39
41
|
end
|
40
42
|
|
41
|
-
# @todo copied from ActiveRecord::ConnectionAdapters::SchemaStatements v5.2.2
|
42
|
-
# Why version column type of String, but insert to Integer?
|
43
|
-
def assume_migrated_upto_version(version, migrations_paths)
|
44
|
-
migrations_paths = Array(migrations_paths)
|
45
|
-
version = version.to_i
|
46
|
-
sm_table = quote_table_name(ActiveRecord::SchemaMigration.table_name)
|
47
|
-
|
48
|
-
migrated = ActiveRecord::SchemaMigration.all_versions.map(&:to_i)
|
49
|
-
versions = migration_context.migration_files.map do |file|
|
50
|
-
migration_context.parse_migration_filename(file).first.to_i
|
51
|
-
end
|
52
|
-
|
53
|
-
unless migrated.include?(version)
|
54
|
-
do_execute( "INSERT INTO #{sm_table} (version) VALUES (#{quote(version.to_s)})", 'SchemaMigration', format: nil)
|
55
|
-
end
|
56
|
-
|
57
|
-
inserting = (versions - migrated).select { |v| v < version }
|
58
|
-
if inserting.any?
|
59
|
-
if (duplicate = inserting.detect { |v| inserting.count(v) > 1 })
|
60
|
-
raise "Duplicate migration #{duplicate}. Please renumber your migrations to resolve the conflict."
|
61
|
-
end
|
62
|
-
if supports_multi_insert?
|
63
|
-
do_system_execute insert_versions_sql(inserting.map(&:to_s))
|
64
|
-
else
|
65
|
-
inserting.each do |v|
|
66
|
-
do_system_execute insert_versions_sql(v)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
43
|
# Not indexes on clickhouse
|
73
44
|
def indexes(table_name, name = nil)
|
74
45
|
[]
|
@@ -86,21 +57,22 @@ module ActiveRecord
|
|
86
57
|
end
|
87
58
|
end
|
88
59
|
|
89
|
-
|
90
|
-
|
91
|
-
def apply_format(sql, format)
|
92
|
-
format ? "#{sql} FORMAT #{format}" : sql
|
93
|
-
end
|
94
|
-
|
95
|
-
def do_execute(sql, name = nil, format: 'JSONCompact')
|
60
|
+
def do_execute(sql, name = nil, format: 'JSONCompact', settings: {})
|
96
61
|
log(sql, "#{adapter_name} #{name}") do
|
97
62
|
formatted_sql = apply_format(sql, format)
|
98
|
-
|
63
|
+
request_params = @config || {}
|
64
|
+
res = @connection.post("/?#{request_params.merge(settings).to_param}", formatted_sql)
|
99
65
|
|
100
66
|
process_response(res)
|
101
67
|
end
|
102
68
|
end
|
103
69
|
|
70
|
+
private
|
71
|
+
|
72
|
+
def apply_format(sql, format)
|
73
|
+
format ? "#{sql} FORMAT #{format}" : sql
|
74
|
+
end
|
75
|
+
|
104
76
|
def process_response(res)
|
105
77
|
case res.code.to_i
|
106
78
|
when 200
|
@@ -109,6 +81,8 @@ module ActiveRecord
|
|
109
81
|
raise ActiveRecord::ActiveRecordError,
|
110
82
|
"Response code: #{res.code}:\n#{res.body}"
|
111
83
|
end
|
84
|
+
rescue JSON::ParserError
|
85
|
+
res.body
|
112
86
|
end
|
113
87
|
|
114
88
|
def log_with_debug(sql, name = nil)
|
@@ -121,7 +95,11 @@ module ActiveRecord
|
|
121
95
|
end
|
122
96
|
|
123
97
|
def create_table_definition(*args)
|
124
|
-
|
98
|
+
if ActiveRecord::version >= Gem::Version.new('6')
|
99
|
+
Clickhouse::TableDefinition.new(self, *args)
|
100
|
+
else
|
101
|
+
Clickhouse::TableDefinition.new(*args)
|
102
|
+
end
|
125
103
|
end
|
126
104
|
|
127
105
|
def new_column_from_field(table_name, field)
|
@@ -130,7 +108,11 @@ module ActiveRecord
|
|
130
108
|
default = field[3]
|
131
109
|
default_value = extract_value_from_default(default)
|
132
110
|
default_function = extract_default_function(default_value, default)
|
133
|
-
|
111
|
+
if ActiveRecord::version >= Gem::Version.new('6')
|
112
|
+
ClickhouseColumn.new(field[0], default_value, type_metadata, field[1].include?('Nullable'), default_function)
|
113
|
+
else
|
114
|
+
ClickhouseColumn.new(field[0], default_value, type_metadata, field[1].include?('Nullable'), table_name, default_function)
|
115
|
+
end
|
134
116
|
end
|
135
117
|
|
136
118
|
protected
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'clickhouse-activerecord/arel/visitors/to_sql'
|
4
|
-
require '
|
4
|
+
require 'clickhouse-activerecord/arel/table'
|
5
5
|
require 'active_record/connection_adapters/clickhouse/oid/date'
|
6
6
|
require 'active_record/connection_adapters/clickhouse/oid/date_time'
|
7
7
|
require 'active_record/connection_adapters/clickhouse/oid/big_integer'
|
@@ -18,6 +18,7 @@ module ActiveRecord
|
|
18
18
|
config = config.symbolize_keys
|
19
19
|
host = config[:host] || 'localhost'
|
20
20
|
port = config[:port] || 8123
|
21
|
+
ssl = config[:ssl].present? ? config[:ssl] : port == 443
|
21
22
|
|
22
23
|
if config.key?(:database)
|
23
24
|
database = config[:database]
|
@@ -25,7 +26,30 @@ module ActiveRecord
|
|
25
26
|
raise ArgumentError, 'No database specified. Missing argument: database.'
|
26
27
|
end
|
27
28
|
|
28
|
-
ConnectionAdapters::ClickhouseAdapter.new(
|
29
|
+
ConnectionAdapters::ClickhouseAdapter.new(logger, [host, port, ssl], { user: config[:username], password: config[:password], database: database }.compact, config)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Relation
|
35
|
+
|
36
|
+
# Replace for only ClickhouseAdapter
|
37
|
+
def reverse_order!
|
38
|
+
orders = order_values.uniq
|
39
|
+
orders.reject!(&:blank?)
|
40
|
+
if self.connection.is_a?(ConnectionAdapters::ClickhouseAdapter) && orders.empty? && !primary_key
|
41
|
+
self.order_values = %w(date created_at).select {|c| column_names.include?(c) }.map{|c| arel_attribute(c).desc }
|
42
|
+
else
|
43
|
+
self.order_values = reverse_sql_order(orders)
|
44
|
+
end
|
45
|
+
self
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module TypeCaster
|
50
|
+
class Map
|
51
|
+
def is_view
|
52
|
+
types.is_view
|
29
53
|
end
|
30
54
|
end
|
31
55
|
end
|
@@ -39,6 +63,11 @@ module ActiveRecord
|
|
39
63
|
def is_view=(value)
|
40
64
|
@is_view = value
|
41
65
|
end
|
66
|
+
|
67
|
+
def arel_table # :nodoc:
|
68
|
+
@arel_table ||= ClickhouseActiverecord::Arel::Table.new(table_name, type_caster: type_caster)
|
69
|
+
end
|
70
|
+
|
42
71
|
end
|
43
72
|
end
|
44
73
|
|
@@ -64,17 +93,34 @@ module ActiveRecord
|
|
64
93
|
include Clickhouse::SchemaStatements
|
65
94
|
|
66
95
|
# Initializes and connects a Clickhouse adapter.
|
67
|
-
def initialize(
|
68
|
-
super(
|
96
|
+
def initialize(logger, connection_parameters, config, full_config)
|
97
|
+
super(nil, logger)
|
69
98
|
@connection_parameters = connection_parameters
|
70
99
|
@config = config
|
71
|
-
@debug = debug
|
100
|
+
@debug = full_config[:debug] || false
|
101
|
+
@full_config = full_config
|
72
102
|
|
73
103
|
@prepared_statements = false
|
104
|
+
if ActiveRecord::version == Gem::Version.new('6.0.0')
|
105
|
+
@prepared_statement_status = Concurrent::ThreadLocalVar.new(false)
|
106
|
+
end
|
74
107
|
|
75
108
|
connect
|
76
109
|
end
|
77
110
|
|
111
|
+
# Support SchemaMigration from v5.2.2 to v6+
|
112
|
+
def schema_migration # :nodoc:
|
113
|
+
if ActiveRecord::version >= Gem::Version.new('6')
|
114
|
+
super
|
115
|
+
else
|
116
|
+
ActiveRecord::SchemaMigration
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def migrations_paths
|
121
|
+
@full_config[:migrations_paths] || 'db/migrate_clickhouse'
|
122
|
+
end
|
123
|
+
|
78
124
|
def arel_visitor # :nodoc:
|
79
125
|
ClickhouseActiverecord::Arel::Visitors::ToSql.new(self)
|
80
126
|
end
|
@@ -130,6 +176,14 @@ module ActiveRecord
|
|
130
176
|
value.to_s(:db)
|
131
177
|
end
|
132
178
|
|
179
|
+
def column_name_for_operation(operation, node) # :nodoc:
|
180
|
+
if ActiveRecord::version >= Gem::Version.new('6')
|
181
|
+
visitor.compile(node)
|
182
|
+
else
|
183
|
+
column_name_from_arel_node(node)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
133
187
|
# Executes insert +sql+ statement in the context of this connection using
|
134
188
|
# +binds+ as the bind substitutes. +name+ is logged along with
|
135
189
|
# the executed +sql+ statement.
|
@@ -177,8 +231,7 @@ module ActiveRecord
|
|
177
231
|
private
|
178
232
|
|
179
233
|
def connect
|
180
|
-
|
181
|
-
@connection = Net::HTTP.start(@connection_parameters[0], @connection_parameters[1], use_ssl: @connection_parameters[1] == 443)
|
234
|
+
@connection = Net::HTTP.start(@connection_parameters[0], @connection_parameters[1], use_ssl: @connection_parameters[2], verify_mode: OpenSSL::SSL::VERIFY_NONE)
|
182
235
|
end
|
183
236
|
end
|
184
237
|
end
|
@@ -6,13 +6,12 @@ module ClickhouseActiverecord
|
|
6
6
|
class ToSql < ::Arel::Visitors::ToSql
|
7
7
|
|
8
8
|
def aggregate(name, o, collector)
|
9
|
-
# todo how get model class from request? This method works with only rails 4.2.
|
10
9
|
# replacing function name for materialized view
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
if o.expressions.first && o.expressions.first != '*' && !o.expressions.first.is_a?(String) && o.expressions.first.relation&.is_view
|
11
|
+
super("#{name.downcase}Merge", o, collector)
|
12
|
+
else
|
14
13
|
super
|
15
|
-
|
14
|
+
end
|
16
15
|
end
|
17
16
|
|
18
17
|
end
|
@@ -31,13 +31,27 @@ module ClickhouseActiverecord
|
|
31
31
|
create
|
32
32
|
end
|
33
33
|
|
34
|
+
def structure_dump(*args)
|
35
|
+
tables = connection.execute("SHOW TABLES FROM #{@configuration['database']}")['data'].flatten
|
36
|
+
|
37
|
+
File.open(args.first, 'w:utf-8') do |file|
|
38
|
+
tables.each do |table|
|
39
|
+
next if table.match(/\.inner/)
|
40
|
+
file.puts connection.execute("SHOW CREATE TABLE #{table}")['data'].try(:first).try(:first).gsub("#{@configuration['database']}.", '') + ";\n\n"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def structure_load(*args)
|
46
|
+
File.read(args.first).split(";\n\n").each { |sql| connection.execute(sql) }
|
47
|
+
end
|
48
|
+
|
34
49
|
def migrate
|
35
50
|
check_target_version
|
36
51
|
|
37
52
|
verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] != "false" : true
|
38
53
|
scope = ENV["SCOPE"]
|
39
54
|
verbose_was, ActiveRecord::Migration.verbose = ActiveRecord::Migration.verbose, verbose
|
40
|
-
binding.pry
|
41
55
|
connection.migration_context.migrate(target_version) do |migration|
|
42
56
|
scope.blank? || scope == migration.scope
|
43
57
|
end
|
@@ -6,6 +6,20 @@ class ClickhouseMigrationGenerator < ActiveRecord::Generators::MigrationGenerato
|
|
6
6
|
def create_migration_file
|
7
7
|
set_local_assigns!
|
8
8
|
validate_file_name!
|
9
|
-
migration_template @migration_template, "
|
9
|
+
migration_template @migration_template, File.join(db_migrate_path, "#{file_name}.rb")
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def db_migrate_path
|
15
|
+
if defined?(Rails.application) && Rails.application
|
16
|
+
configured_migrate_path || default_migrate_path
|
17
|
+
else
|
18
|
+
default_migrate_path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def default_migrate_path
|
23
|
+
"db/migrate_clickhouse"
|
10
24
|
end
|
11
25
|
end
|
data/lib/tasks/clickhouse.rake
CHANGED
@@ -27,6 +27,18 @@ namespace :clickhouse do
|
|
27
27
|
|
28
28
|
end
|
29
29
|
|
30
|
+
namespace :structure do
|
31
|
+
desc 'Load database structure'
|
32
|
+
task load: [:load_config, 'db:check_protected_environments'] do
|
33
|
+
ClickhouseActiverecord::Tasks.new(ActiveRecord::Base.configurations["#{Rails.env}_clickhouse"]).structure_load("#{Rails.root}/db/clickhouse_structure.sql")
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Dump database structure'
|
37
|
+
task dump: [:load_config, 'db:check_protected_environments'] do
|
38
|
+
ClickhouseActiverecord::Tasks.new(ActiveRecord::Base.configurations["#{Rails.env}_clickhouse"]).structure_dump("#{Rails.root}/db/clickhouse_structure.sql")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
30
42
|
desc 'Creates the database from DATABASE_URL or config/database.yml'
|
31
43
|
task create: [:load_config] do
|
32
44
|
ActiveRecord::Tasks::DatabaseTasks.create(ActiveRecord::Base.configurations["#{Rails.env}_clickhouse"])
|
metadata
CHANGED
@@ -1,22 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clickhouse-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.12
|
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: 2020-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.13'
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: 1.13.4
|
@@ -24,9 +21,6 @@ dependencies:
|
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '1.13'
|
30
24
|
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
26
|
version: 1.13.4
|
@@ -34,14 +28,14 @@ dependencies:
|
|
34
28
|
name: activerecord
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
|
-
- - "
|
31
|
+
- - ">="
|
38
32
|
- !ruby/object:Gem::Version
|
39
33
|
version: '5.2'
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
|
-
- - "
|
38
|
+
- - ">="
|
45
39
|
- !ruby/object:Gem::Version
|
46
40
|
version: '5.2'
|
47
41
|
- !ruby/object:Gem::Dependency
|
@@ -126,6 +120,7 @@ files:
|
|
126
120
|
- lib/active_record/connection_adapters/clickhouse/schema_statements.rb
|
127
121
|
- lib/active_record/connection_adapters/clickhouse_adapter.rb
|
128
122
|
- lib/clickhouse-activerecord.rb
|
123
|
+
- lib/clickhouse-activerecord/arel/table.rb
|
129
124
|
- lib/clickhouse-activerecord/arel/visitors/to_sql.rb
|
130
125
|
- lib/clickhouse-activerecord/railtie.rb
|
131
126
|
- lib/clickhouse-activerecord/schema_dumper.rb
|