PNixx / clickhouse-activerecord

A Ruby database ActiveRecord driver for ClickHouse
MIT License
202 stars 100 forks source link

clickhouse:structure:dump throws an error in rails_70 branch #131

Open AlexKichkailo opened 8 months ago

AlexKichkailo commented 8 months ago

When running bin/rails clickhouse:structure:dump I am getting the following error

throws NoMethodError: undefined method `with_indifferent_access' for #<ActiveRecord::DatabaseConfigurations::HashConfig

      @configuration = configuration.with_indifferent_access
                                    ^^^^^^^^^^^^^^^^^^^^^^^^
/src/vendor/bundle/ruby/3.1.0/gems/clickhouse-activerecord-0.6.2/lib/clickhouse-activerecord/tasks.rb:8:in `initialize'
/src/vendor/bundle/ruby/3.1.0/gems/clickhouse-activerecord-0.6.2/lib/tasks/clickhouse.rake:48:in `new'
/src/vendor/bundle/ruby/3.1.0/gems/clickhouse-activerecord-0.6.2/lib/tasks/clickhouse.rake:48:in `block (3 levels) in <top (required)>'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `block in execute'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `each'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `execute'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:188:in `invoke'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:182:in `invoke_task'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block (2 levels) in top_level'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `each'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block in top_level'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:147:in `run_with_threads'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:132:in `top_level'
/src/vendor/bundle/ruby/3.1.0/gems/railties-7.0.8.1/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:208:in `standard_exception_handling'
/src/vendor/bundle/ruby/3.1.0/gems/railties-7.0.8.1/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/src/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/rake_module.rb:59:in `with_application'
/src/vendor/bundle/ruby/3.1.0/gems/railties-7.0.8.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/src/vendor/bundle/ruby/3.1.0/gems/railties-7.0.8.1/lib/rails/command.rb:51:in `invoke'
/src/vendor/bundle/ruby/3.1.0/gems/railties-7.0.8.1/lib/rails/commands.rb:18:in `<top (required)>'

Appears to be an issue in rails_70 branch.

senid231 commented 4 months ago

temp fix

ClickhouseActiverecord::Tasks.class_eval do
  def initialize(configuration)
    # sometimes configuration is an instance of ActiveRecord::DatabaseConfigurations::HashConfig
    # and sometimes it's a Hash
    @configuration = if configuration.respond_to?(:configuration_hash)
                       configuration.configuration_hash.with_indifferent_access
                     else
                       configuration.with_indifferent_access
                     end
  end
end