cockroachdb / activerecord-cockroachdb-adapter

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

Rails 7 version throws "PG::UndefinedObject" #257

Open aemadrid-twx opened 2 years ago

aemadrid-twx commented 2 years ago
❯ bundle show activerecord-cockroachdb-adapter
/Users/some_user/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/activerecord-cockroachdb-adapter-7.0.0

❯ bundle show rails
/Users/some_user/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/rails-7.0.3.1

❯ ruby -v
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [arm64-darwin21]

❯  be rake db:create
Created database 'some_app_development'
PG::UndefinedObject: ERROR:  unrecognized configuration parameter "crdb_version"
Couldn't create 'some_app_development' database. Please check your configuration.
rake aborted!
ActiveRecord::ConnectionNotEstablished: PG::UndefinedObject: ERROR:  unrecognized configuration parameter "crdb_version"
/Users/some_user/.asdf/installs/ruby/3.1.1/bin/bundle:25:in `load'
/Users/some_user/.asdf/installs/ruby/3.1.1/bin/bundle:25:in `<main>'
rafiss commented 2 years ago

Could you share your CockroachDB version and your rails database configuration (or URL) you used to connect?

aemadrid-twx commented 2 years ago

Cockroach V22.1.4

default: &default
  adapter: cockroachdb
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: some_app_development
  host: localhost
  port: 26257
  user: root
  password: ""
  sslmode: disable
aemadrid-twx commented 2 years ago

BTW tested this in a Rails 6 app with the 6.1.10 adapter and it works as expected.

❯ bundle exec rake db:create
Created database 'some_app_development'
Created database 'some_app_test'

❯ ruby -v
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [arm64-darwin21]

❯ bundle show rails
/Users/some_user/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/rails-6.1.6.1

❯ bundle show activerecord-cockroachdb-adapter
/Users/some_user/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/activerecord-cockroachdb-adapter-6.1.10
rafiss commented 2 years ago

I haven't been able to reproduce this. If possible, could you upload your code to a repo or a gist so i can try running it myself?

The unrecognized configuration parameter "crdb_version" error makes me think that it's somehow connecting to Postgres instead of CRDB.

adamjgrant commented 1 year ago

I'm having the same issue with Rails 7.

$ bundle exec rake db:create
PG::UndefinedObject: ERROR:  unrecognized configuration parameter "crdb_version"
Couldn't create 'defaultdb' database. Please check your configuration.

Using gem "activerecord-cockroachdb-adapter", "~> 7.0.0" in Gemfile

database.yml


default: &default
  adapter: cockroachdb
  url: <%= ENV['ADAMSGPT_COCKROACHDB_DATABASE_URL'] %>
  database: defaultdb
  sslrootcert: './.postgresql/root.crt'
  sslmode: verify-full

development:
  <<: *default

production:
  <<: *default
adamjgrant commented 1 year ago
bundle show activerecord-cockroachdb-adapter
/Users/adamgrant/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activerecord-cockroachdb-adapter-7.0.0

bundle show rails
/Users/adamgrant/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rails-7.0.4.3

ruby -v
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [arm64-darwin22]
adamjgrant commented 1 year ago

Strangely I ran it again today and it worked just fine. 🤷🏻