clickhouse-activerecord 0.4.12 → 0.5.0

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: ad0ad1c7545498f275ff975d35ee9dde7d2f644516932ee33ab65796360426a0
4
- data.tar.gz: 15b32b155c596c8cdd9e187681a128a4806ca7e2c457e0f833ffc66ba9c994af
3
+ metadata.gz: 1e17583f619debbb02952aa4299fedebbdd0de5ff6ae5c4a604071e42381c33a
4
+ data.tar.gz: d9d642a756c2ff7791081f1298917d96758dd5de4f07781dc7c9e587100536b4
5
5
  SHA512:
6
- metadata.gz: 8f80ffc1c70dbbdd489ea59627e85a72f538276c80adc0fe5ee4319c222a61da2acd1680ea42bd8c4c4b713fb354f7498a3469cc3cfd17f9003c8dbd607719b2
7
- data.tar.gz: 9c91108f18bb9b133708a682ee3dfec238cc54afac480fcada95e876bb051843a7269e3d81c6298299b1bbffbc5a8a47975add7919144d220845fd87c710122b
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 < AbstractAdapter::SchemaCreation# :nodoc:
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
- if options[:options].present?
25
- create_sql << " ENGINE = #{options[:options]}"
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, table_options(o)) if !o.view || o.view && o.materialized
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(*args)
120
- Clickhouse::TableDefinition.new(self, *args)
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)
@@ -59,7 +59,11 @@ module ActiveRecord
59
59
  module TypeCaster
60
60
  class Map
61
61
  def is_view
62
- types.is_view
62
+ if @klass.respond_to?(:is_view)
63
+ @klass.is_view # rails 6.1
64
+ else
65
+ types.is_view # less than 6.1
66
+ end
63
67
  end
64
68
  end
65
69
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ClickhouseActiverecord
2
- VERSION = '0.4.12'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -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.12
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-04-02 00:00:00.000000000 Z
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler