Skip to content

Commit

Permalink
fix schema load #108
Browse files Browse the repository at this point in the history
  • Loading branch information
PNixx committed Jan 12, 2024
1 parent 3b5f651 commit 0800f57
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ def datetime(*args, **options)

if options[:precision]
kind = :datetime64
options[:value] = options[:precision]
end

args.each { |name| column(name, kind, **options.except(:precision)) }
args.each { |name| column(name, kind, **options) }
end

def uuid(*args, **options)
Expand Down
12 changes: 0 additions & 12 deletions lib/clickhouse-activerecord/schema.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
# frozen_string_literal: true

module ClickhouseActiverecord

class Schema < ::ActiveRecord::Schema

def define(info, &block) # :nodoc:
instance_eval(&block)

if info[:version].present?
connection.schema_migration.create_table
connection.assume_migrated_upto_version(info[:version], ClickhouseActiverecord::Migrator.migrations_paths)
end

ClickhouseActiverecord::InternalMetadata.create_table
ClickhouseActiverecord::InternalMetadata[:environment] = connection.migration_context.current_environment
end
end
end
2 changes: 1 addition & 1 deletion lib/clickhouse-activerecord/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ClickhouseActiverecord
VERSION = '1.0.1'
VERSION = '1.0.2'
end
5 changes: 3 additions & 2 deletions lib/tasks/clickhouse.rake
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ namespace :clickhouse do
namespace :schema do
# TODO: not testing
desc 'Load database schema'
task load: %i[load_config prepare_internal_metadata_table] do
task load: %i[prepare_internal_metadata_table] do
simple = ENV['simple'] || ARGV.any? { |a| a.include?('--simple') } ? '_simple' : nil
ClickhouseActiverecord::SchemaMigration.drop_table
config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
ClickhouseActiverecord::SchemaMigration.new(ActiveRecord::Base.establish_connection(config).connection).drop_table
load(Rails.root.join("db/clickhouse_schema#{simple}.rb"))
end

Expand Down
10 changes: 4 additions & 6 deletions spec/cases/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,17 @@ class Model < ActiveRecord::Base
let(:record) { model.create!(event_name: 'some event', date: date) }

it 'raises an error' do
expect {
record.update!(event_name: 'new event name')
}.to raise_error(ActiveRecord::ActiveRecordError, 'Clickhouse update is not supported')
record.update!(event_name: 'new event name')
expect(model.where(event_name: 'new event name').count).to eq(1)
end
end

describe '#destroy' do
let(:record) { model.create!(event_name: 'some event', date: date) }

it 'raises an error' do
expect {
record.destroy!
}.to raise_error(ActiveRecord::ActiveRecordError, 'Clickhouse delete is not supported')
record.destroy!
expect(model.count).to eq(0)
end
end

Expand Down

0 comments on commit 0800f57

Please sign in to comment.