clickhouse-activerecord 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,47 +1,45 @@
1
1
  module CoreExtensions
2
2
  module ActiveRecord
3
3
  module SchemaMigration
4
- module ClassMethods
5
4
 
6
- def create_table
7
- return super unless connection.is_a?(::ActiveRecord::ConnectionAdapters::ClickhouseAdapter)
5
+ def create_table
6
+ return super unless connection.is_a?(::ActiveRecord::ConnectionAdapters::ClickhouseAdapter)
8
7
 
9
- return if table_exists?
8
+ return if table_exists?
10
9
 
11
- version_options = connection.internal_string_options_for_primary_key
12
- table_options = {
13
- id: false, options: 'ReplacingMergeTree(ver) ORDER BY (version)', if_not_exists: true
14
- }
15
- full_config = connection.instance_variable_get(:@config) || {}
10
+ version_options = connection.internal_string_options_for_primary_key
11
+ table_options = {
12
+ id: false, options: 'ReplacingMergeTree(ver) ORDER BY (version)', if_not_exists: true
13
+ }
14
+ full_config = connection.instance_variable_get(:@config) || {}
16
15
 
17
- if full_config[:distributed_service_tables]
18
- table_options.merge!(with_distributed: table_name, sharding_key: 'cityHash64(version)')
16
+ if full_config[:distributed_service_tables]
17
+ table_options.merge!(with_distributed: table_name, sharding_key: 'cityHash64(version)')
19
18
 
20
- distributed_suffix = "_#{full_config[:distributed_service_tables_suffix] || 'distributed'}"
21
- else
22
- distributed_suffix = ''
23
- end
19
+ distributed_suffix = "_#{full_config[:distributed_service_tables_suffix] || 'distributed'}"
20
+ else
21
+ distributed_suffix = ''
22
+ end
24
23
 
25
- connection.create_table(table_name + distributed_suffix.to_s, **table_options) do |t|
26
- t.string :version, **version_options
27
- t.column :active, 'Int8', null: false, default: '1'
28
- t.datetime :ver, null: false, default: -> { 'now()' }
29
- end
24
+ connection.create_table(table_name + distributed_suffix.to_s, **table_options) do |t|
25
+ t.string :version, **version_options
26
+ t.column :active, 'Int8', null: false, default: '1'
27
+ t.datetime :ver, null: false, default: -> { 'now()' }
30
28
  end
29
+ end
31
30
 
32
- def delete_version(version)
33
- return super unless connection.is_a?(::ActiveRecord::ConnectionAdapters::ClickhouseAdapter)
31
+ def delete_version(version)
32
+ return super unless connection.is_a?(::ActiveRecord::ConnectionAdapters::ClickhouseAdapter)
34
33
 
35
- im = Arel::InsertManager.new(arel_table)
36
- im.insert(arel_table[primary_key] => version.to_s, arel_table['active'] => 0)
37
- connection.insert(im, "#{self.class} Create Rollback Version", primary_key, version)
38
- end
34
+ im = ::Arel::InsertManager.new(arel_table)
35
+ im.insert(arel_table[primary_key] => version.to_s, arel_table['active'] => 0)
36
+ connection.insert(im, "#{self.class} Create Rollback Version", primary_key, version)
37
+ end
39
38
 
40
- def all_versions
41
- return super unless connection.is_a?(::ActiveRecord::ConnectionAdapters::ClickhouseAdapter)
39
+ def all_versions
40
+ return super unless connection.is_a?(::ActiveRecord::ConnectionAdapters::ClickhouseAdapter)
42
41
 
43
- final.where(active: 1).order(:version).pluck(:version)
44
- end
42
+ final.where(active: 1).order(:version).pluck(:version)
45
43
  end
46
44
  end
47
45
  end
@@ -15,15 +15,18 @@ namespace :clickhouse do
15
15
  # TODO: deprecated
16
16
  desc 'Load database schema'
17
17
  task load: %i[prepare_internal_metadata_table] do
18
+ puts 'Warning: `rake clickhouse:schema:load` is deprecated! Use `rake db:schema:load:clickhouse` instead'
18
19
  simple = ENV['simple'] || ARGV.any? { |a| a.include?('--simple') } ? '_simple' : nil
19
20
  ActiveRecord::Base.establish_connection(:clickhouse)
20
- ActiveRecord::SchemaMigration.drop_table
21
+ connection = ActiveRecord::Tasks::DatabaseTasks.migration_connection
22
+ connection.schema_migration.drop_table
21
23
  load(Rails.root.join("db/clickhouse_schema#{simple}.rb"))
22
24
  end
23
25
 
24
26
  # TODO: deprecated
25
27
  desc 'Dump database schema'
26
28
  task dump: :environment do |_, args|
29
+ puts 'Warning: `rake clickhouse:schema:dump` is deprecated! Use `rake db:schema:dump:clickhouse` instead'
27
30
  simple = ENV['simple'] || args[:simple] || ARGV.any? { |a| a.include?('--simple') } ? '_simple' : nil
28
31
  filename = Rails.root.join("db/clickhouse_schema#{simple}.rb")
29
32
  File.open(filename, 'w:utf-8') do |file|
@@ -36,43 +39,38 @@ namespace :clickhouse do
36
39
  namespace :structure do
37
40
  desc 'Load database structure'
38
41
  task load: ['db:check_protected_environments'] do
39
- config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
40
42
  ClickhouseActiverecord::Tasks.new(config).structure_load(Rails.root.join('db/clickhouse_structure.sql'))
41
43
  end
42
44
 
43
45
  desc 'Dump database structure'
44
46
  task dump: ['db:check_protected_environments'] do
45
- config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
46
47
  ClickhouseActiverecord::Tasks.new(config).structure_dump(Rails.root.join('db/clickhouse_structure.sql'))
47
48
  end
48
49
  end
49
50
 
50
51
  desc 'Creates the database from DATABASE_URL or config/database.yml'
51
52
  task create: [] do
52
- config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
53
- ActiveRecord::Tasks::DatabaseTasks.create(config)
53
+ puts 'Warning: `rake clickhouse:create` is deprecated! Use `rake db:create:clickhouse` instead'
54
54
  end
55
55
 
56
56
  desc 'Drops the database from DATABASE_URL or config/database.yml'
57
57
  task drop: ['db:check_protected_environments'] do
58
- config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
59
- ActiveRecord::Tasks::DatabaseTasks.drop(config)
58
+ puts 'Warning: `rake clickhouse:drop` is deprecated! Use `rake db:drop:clickhouse` instead'
60
59
  end
61
60
 
62
61
  desc 'Empty the database from DATABASE_URL or config/database.yml'
63
62
  task purge: ['db:check_protected_environments'] do
64
- config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
65
- ActiveRecord::Tasks::DatabaseTasks.purge(config)
63
+ puts 'Warning: `rake clickhouse:purge` is deprecated! Use `rake db:reset:clickhouse` instead'
66
64
  end
67
65
 
68
66
  # desc 'Resets your database using your migrations for the current environment'
69
67
  task :reset do
70
- Rake::Task['clickhouse:purge'].execute
71
- Rake::Task['clickhouse:migrate'].execute
68
+ puts 'Warning: `rake clickhouse:reset` is deprecated! Use `rake db:reset:clickhouse` instead'
72
69
  end
73
70
 
74
71
  desc 'Migrate the clickhouse database'
75
72
  task migrate: %i[prepare_schema_migration_table prepare_internal_metadata_table] do
73
+ puts 'Warning: `rake clickhouse:migrate` is deprecated! Use `rake db:migrate:clickhouse` instead'
76
74
  Rake::Task['db:migrate:clickhouse'].execute
77
75
  if File.exist? "#{Rails.root}/db/clickhouse_schema_simple.rb"
78
76
  Rake::Task['clickhouse:schema:dump'].execute(simple: true)
@@ -81,9 +79,14 @@ namespace :clickhouse do
81
79
 
82
80
  desc 'Rollback the clickhouse database'
83
81
  task rollback: %i[prepare_schema_migration_table prepare_internal_metadata_table] do
82
+ puts 'Warning: `rake clickhouse:rollback` is deprecated! Use `rake db:rollback:clickhouse` instead'
84
83
  Rake::Task['db:rollback:clickhouse'].execute
85
84
  if File.exist? "#{Rails.root}/db/clickhouse_schema_simple.rb"
86
85
  Rake::Task['clickhouse:schema:dump'].execute(simple: true)
87
86
  end
88
87
  end
88
+
89
+ def config
90
+ ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
91
+ end
89
92
  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: 1.0.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Odintsov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-02 00:00:00.000000000 Z
11
+ date: 2024-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,14 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".docker/clickhouse/cluster/server1_config.xml"
91
+ - ".docker/clickhouse/cluster/server2_config.xml"
92
+ - ".docker/clickhouse/single/config.xml"
93
+ - ".docker/clickhouse/users.xml"
94
+ - ".docker/docker-compose.cluster.yml"
95
+ - ".docker/docker-compose.yml"
96
+ - ".docker/nginx/local.conf"
97
+ - ".github/workflows/testing.yml"
90
98
  - ".gitignore"
91
99
  - ".rspec"
92
100
  - CHANGELOG.md
@@ -98,7 +106,6 @@ files:
98
106
  - bin/console
99
107
  - bin/setup
100
108
  - clickhouse-activerecord.gemspec
101
- - core_extensions/active_record/migration/command_recorder.rb
102
109
  - lib/active_record/connection_adapters/clickhouse/oid/array.rb
103
110
  - lib/active_record/connection_adapters/clickhouse/oid/big_integer.rb
104
111
  - lib/active_record/connection_adapters/clickhouse/oid/date.rb
@@ -119,6 +126,7 @@ files:
119
126
  - lib/clickhouse-activerecord/tasks.rb
120
127
  - lib/clickhouse-activerecord/version.rb
121
128
  - lib/core_extensions/active_record/internal_metadata.rb
129
+ - lib/core_extensions/active_record/migration/command_recorder.rb
122
130
  - lib/core_extensions/active_record/relation.rb
123
131
  - lib/core_extensions/active_record/schema_migration.rb
124
132
  - lib/core_extensions/arel/nodes/select_core.rb
@@ -146,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
154
  - !ruby/object:Gem::Version
147
155
  version: '0'
148
156
  requirements: []
149
- rubygems_version: 3.1.6
157
+ rubygems_version: 3.3.7
150
158
  signing_key:
151
159
  specification_version: 4
152
160
  summary: ClickHouse ActiveRecord