clickhouse-activerecord 0.4.12 → 0.5.0
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/lib/active_record/connection_adapters/clickhouse/schema_creation.rb +17 -6
- data/lib/active_record/connection_adapters/clickhouse/schema_statements.rb +2 -2
- data/lib/active_record/connection_adapters/clickhouse_adapter.rb +5 -1
- data/lib/clickhouse-activerecord/migration.rb +3 -1
- data/lib/clickhouse-activerecord/tasks.rb +1 -1
- data/lib/clickhouse-activerecord/version.rb +1 -1
- data/lib/generators/clickhouse_migration_generator.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: 1e17583f619debbb02952aa4299fedebbdd0de5ff6ae5c4a604071e42381c33a
|
4
|
+
data.tar.gz: d9d642a756c2ff7791081f1298917d96758dd5de4f07781dc7c9e587100536b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cca1c4ce673a6622855a860e51b85952b0b09e3cbaaafe6b817a5c95ff1bb90d33da4974908acecaed6a658f7574fbaf9f71c1497d1c527006eb36bc3aaefab3
|
7
|
+
data.tar.gz: 344cc941b595fe40179c8974dfc371dd3732cbf8994999d75976506582d23abbda39340e7b2232cc7b7c25f1c6271d3f26325c409cfd7aa21f1acfc017fb8d32
|
@@ -1,9 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
begin
|
3
|
+
require "active_record/connection_adapters/deduplicable"
|
4
|
+
rescue LoadError => e
|
5
|
+
# Rails < 6.1 does not have this file in this location, ignore
|
6
|
+
end
|
7
|
+
|
8
|
+
require "active_record/connection_adapters/abstract/schema_creation"
|
2
9
|
|
3
10
|
module ActiveRecord
|
4
11
|
module ConnectionAdapters
|
5
12
|
module Clickhouse
|
6
|
-
class SchemaCreation <
|
13
|
+
class SchemaCreation < ConnectionAdapters::SchemaCreation# :nodoc:
|
7
14
|
|
8
15
|
def visit_AddColumnDefinition(o)
|
9
16
|
sql = +"ADD COLUMN #{accept(o.column)}"
|
@@ -21,8 +28,14 @@ module ActiveRecord
|
|
21
28
|
end
|
22
29
|
|
23
30
|
def add_table_options!(create_sql, options)
|
24
|
-
|
25
|
-
|
31
|
+
opts = options[:options]
|
32
|
+
if options.respond_to?(:options)
|
33
|
+
# rails 6.1
|
34
|
+
opts ||= options.options
|
35
|
+
end
|
36
|
+
|
37
|
+
if opts.present?
|
38
|
+
create_sql << " ENGINE = #{opts}"
|
26
39
|
else
|
27
40
|
create_sql << " ENGINE = Log()"
|
28
41
|
end
|
@@ -37,11 +50,9 @@ module ActiveRecord
|
|
37
50
|
|
38
51
|
statements = o.columns.map { |c| accept c }
|
39
52
|
statements << accept(o.primary_keys) if o.primary_keys
|
40
|
-
|
41
53
|
create_sql << "(#{statements.join(', ')})" if statements.present?
|
42
54
|
# Attach options for only table or materialized view
|
43
|
-
add_table_options!(create_sql,
|
44
|
-
|
55
|
+
add_table_options!(create_sql, o) if !o.view || o.view && o.materialized
|
45
56
|
create_sql << " AS #{to_sql(o.as)}" if o.as
|
46
57
|
create_sql
|
47
58
|
end
|
@@ -116,8 +116,8 @@ module ActiveRecord
|
|
116
116
|
Clickhouse::SchemaCreation.new(self)
|
117
117
|
end
|
118
118
|
|
119
|
-
def create_table_definition(
|
120
|
-
Clickhouse::TableDefinition.new(self,
|
119
|
+
def create_table_definition(table_name, options)
|
120
|
+
Clickhouse::TableDefinition.new(self, table_name, **options)
|
121
121
|
end
|
122
122
|
|
123
123
|
def new_column_from_field(table_name, field)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_record/migration'
|
2
|
+
|
1
3
|
module ClickhouseActiverecord
|
2
4
|
|
3
5
|
class SchemaMigration < ::ActiveRecord::SchemaMigration
|
@@ -8,7 +10,7 @@ module ClickhouseActiverecord
|
|
8
10
|
version_options = connection.internal_string_options_for_primary_key
|
9
11
|
|
10
12
|
connection.create_table(table_name, id: false, options: 'ReplacingMergeTree(ver) PARTITION BY version ORDER BY (version)', if_not_exists: true) do |t|
|
11
|
-
t.string :version, version_options
|
13
|
+
t.string :version, **version_options
|
12
14
|
t.column :active, 'Int8', null: false, default: '1'
|
13
15
|
t.datetime :ver, null: false, default: -> { 'now()' }
|
14
16
|
end
|
@@ -6,7 +6,7 @@ module ClickhouseActiverecord
|
|
6
6
|
delegate :connection, :establish_connection, :clear_active_connections!, to: ActiveRecord::Base
|
7
7
|
|
8
8
|
def initialize(configuration)
|
9
|
-
@configuration = configuration
|
9
|
+
@configuration = configuration.with_indifferent_access
|
10
10
|
end
|
11
11
|
|
12
12
|
def create
|
@@ -13,7 +13,7 @@ class ClickhouseMigrationGenerator < ActiveRecord::Generators::MigrationGenerato
|
|
13
13
|
|
14
14
|
def db_migrate_path
|
15
15
|
if defined?(Rails.application) && Rails.application && respond_to?(:configured_migrate_path, true)
|
16
|
-
configured_migrate_path
|
16
|
+
configured_migrate_path || default_migrate_path
|
17
17
|
else
|
18
18
|
default_migrate_path
|
19
19
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Odintsov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|