cockroachdb / activerecord-cockroachdb-adapter

CockroachDB adapter for ActiveRecord.
Apache License 2.0
103 stars 52 forks source link

Rails 7.1 support #296

Closed kkurian closed 7 months ago

kkurian commented 11 months ago

Doesn't build out of the box in Rails 7.1. Relaxing the Rails version in the gemspec allows a build but doesn't result in working system (unless I'm misconfiguring the thing, which is possible; this is my first encounter with cockroachdb).

Shankar1598 commented 11 months ago

We are planning to move our app to Rails 7.1 as well, would be great to have this support

andys commented 10 months ago

Agreed, this gem is the only blocker for upgrading to 7.1

BuonOmo commented 10 months ago

Hi there. I am currently away from my laptop thus cannot work on that before January. If any one of you is willing to work on the topic you can have a look at what has been done on the active-record-postigs-adapter. I'll be available for proofreading.

dikshant commented 10 months ago

Stacktrace I get when I bump rails to 7.1.1

❯ bundle exec rake test

Using cockroachdb
/Users/dikshant/projects/activerecord-cockroachdb-adapter/lib/active_record/connection_adapters/cockroachdb/type.rb:7: warning: method redefined; discarding old adapter_name_from
/opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/type.rb:49: warning: previous definition of adapter_name_from was here
/opt/homebrew/lib/ruby/gems/3.2.0/gems/pg-1.5.4/lib/pg/result.rb:17:in `type_map=': wrong argument type nil (expected PG::TypeMap) (TypeError)

        self.type_map = type_map
                        ^^^^^^^^
    from /opt/homebrew/lib/ruby/gems/3.2.0/gems/pg-1.5.4/lib/pg/result.rb:17:in `map_types!'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:19:in `block (2 levels) in query'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1024:in `block in with_raw_connection'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activesupport/lib/active_support/concurrency/null_lock.rb:9:in `synchronize'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:996:in `with_raw_connection'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:18:in `block in query'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1134:in `log'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:17:in `query'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:100:in `query_value'
    from /Users/dikshant/projects/activerecord-cockroachdb-adapter/lib/active_record/connection_adapters/cockroachdb_adapter.rb:249:in `initialize'
    from /Users/dikshant/projects/activerecord-cockroachdb-adapter/lib/active_record/connection_adapters/cockroachdb_adapter.rb:47:in `new'
    from /Users/dikshant/projects/activerecord-cockroachdb-adapter/lib/active_record/connection_adapters/cockroachdb_adapter.rb:47:in `cockroachdb_connection'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:673:in `public_send'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:673:in `new_connection'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:720:in `checkout_new_connection'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:699:in `try_to_checkout_new_connection'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:657:in `acquire_connection'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `connection'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_adapters/abstract/connection_handler.rb:246:in `retrieve_connection'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_handling.rb:287:in `retrieve_connection'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/lib/active_record/connection_handling.rb:254:in `connection'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/test/support/connection.rb:35:in `connect'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/test/cases/test_case.rb:248:in `<class:TestCase>'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/test/cases/test_case.rb:20:in `<module:ActiveRecord>'
    from /opt/homebrew/lib/ruby/gems/3.2.0/bundler/gems/rails-319256ac4708/activerecord/test/cases/test_case.rb:16:in `<top (required)>'
    from <internal:/opt/homebrew/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from <internal:/opt/homebrew/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from /Users/dikshant/projects/activerecord-cockroachdb-adapter/test/cases/helper.rb:12:in `<top (required)>'
    from <internal:/opt/homebrew/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from <internal:/opt/homebrew/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from /Users/dikshant/projects/activerecord-cockroachdb-adapter/test/cases/helper_cockroachdb.rb:10:in `<top (required)>'
    from <internal:/opt/homebrew/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from <internal:/opt/homebrew/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from /opt/homebrew/lib/ruby/gems/3.2.0/gems/rake-13.1.0/lib/rake/rake_test_loader.rb:21:in `block in <main>'
    from /opt/homebrew/lib/ruby/gems/3.2.0/gems/rake-13.1.0/lib/rake/rake_test_loader.rb:6:in `select'
    from /opt/homebrew/lib/ruby/gems/3.2.0/gems/rake-13.1.0/lib/rake/rake_test_loader.rb:6:in `<main>'
rake aborted!
Command failed with status (1)
/opt/homebrew/lib/ruby/gems/3.2.0/gems/rake-13.1.0/exe/rake:27:in `<top (required)>'
/opt/homebrew/opt/ruby/bin/bundle:25:in `load'
/opt/homebrew/opt/ruby/bin/bundle:25:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)

Diff I applied

❯ git diff
diff --git a/activerecord-cockroachdb-adapter.gemspec b/activerecord-cockroachdb-adapter.gemspec
index 2fb2c45..1325be3 100644
--- a/activerecord-cockroachdb-adapter.gemspec
+++ b/activerecord-cockroachdb-adapter.gemspec
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
   spec.description   = "Allows the use of CockroachDB as a backend for ActiveRecord and Rails apps."
   spec.homepage      = "https://github.com/cockroachdb/activerecord-cockroachdb-adapter"

-  spec.add_dependency "activerecord", "~> 7.0.3"
+  spec.add_dependency "activerecord", "~> 7.1.1"
   spec.add_dependency "pg", "~> 1.2"
   spec.add_dependency "rgeo-activerecord", "~> 7.0.0"
bradpotts commented 10 months ago

I change my adapter: on database.yml from cockroachdb to postgres as a workaround for the type_map error.

BuonOmo commented 9 months ago

@bradpotts if this works, this seems like the issue comes when initializing the gem, we are missing a step that (I assume) wasn't there in 7.0. This narrows down the problem, if someone wants to take a shot at it !

BuonOmo commented 8 months ago

FYI I am working on the topic now. I already found what looks like an impacting change for us in this commit. I'll see how this impact our codebase today.

The bad news is, while bisecting for this error, I found at least one other. I hope there are not too much hidden behind, and will keep you posted!

dikshant commented 7 months ago

7.1 is now supported for this adapter thanks to the work done by @BuonOmo. It available through RubyGems: https://rubygems.org/gems/activerecord-cockroachdb-adapter/versions/7.1.0