rails-sqlserver/activerecord-sqlserver-adapter

Using a gem group breaks the sqlserver adapter

bfcoder opened this issue · 2 comments

Issue

I am upgrading Rails from 7.1 to 7.2. I use a gem group for tiny tds. Rails can't seem to find the adapter anymore.

Expected behavior

Rails should start normally

Actual behavior

Rails errors as it can't find the adapter anymore:

Database configuration specifies nonexistent 'sqlserver' adapter. Available adapters are: mysql2, postgresql, sqlite3, sqlserver, trilogy. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile and that it is at its latest version. If it is up to date, the adapter may need to be modified. (ActiveRecord::AdapterNotFound)

How to reproduce

rails new rails7_2

Add this to your Gemfile

group :tinytds do
  gem 'tiny_tds'
  gem 'activerecord-sqlserver-adapter', '~> 7.2.0'
end

Modify your database.yml

default: &default
  adapter: sqlserver

development:
  <<: *default
  database: dev_project

bundle install

Now run bin/rails c

It will break with the specified error above.

If you remove the gem group:

gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter', '~> 7.2.0'

then the rails console will launch just fine.

Details

  • Rails version: 7.2.2.1
  • SQL Server adapter version: 7.2.3
  • TinyTDS version: 2.1.7 or 3.1.0
  • FreeTDS details: 1.1.24 or 1.4.24
❯ tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds v1.4.24
             freetds.conf directory: /usr/local/etc
     MS db-lib source compatibility: no
        Sybase binary compatibility: no
                      Thread safety: yes
                      iconv library: yes
                        TDS version: auto
                              iODBC: no
                           unixodbc: no
              SSPI "trusted" logins: no
                           Kerberos: no
                            OpenSSL: yes
                             GnuTLS: no
                               MARS: yes

Maybe this is just a new idiosyncrasy with rails 7.2 and nothing is actually wrong with this adapter gem??

Yep, this is just a result of how rails is more intentional about the gem groups.

The fix in my case is to change config/application.rb

Bundler.require(*Rails.groups, :tinytds)

Closing this issue. Sorry for the spam!