Search code examples
ruby-on-railsactiverecordadvantage-database-serverwindows-subsystem-for-linux

forcing an unmaintained ActiveRecord adapter to Rails version 6


I am working on the "Advantage database server" adapter extension, to try and talk to a legacy database that I have access to (that is still in active usage).

I have updated the "Advantage" Gem so that it works on new/active versions of Ruby https://github.com/t12nslookup/advantage and have seen that my copy of the activerecord-advantage-adapter https://github.com/t12nslookup/activerecord_advantage_adapter works on ruby 1.9.3 and rails 3.2.22

I have been working to try to force it to work with rails 6, and have had reasonable success with a simple "ruby" script that "require"s the gems and accesses the data, but I cannot get the same simple database query to work at the rails console.

I'm running in WSL 2, if it makes any difference (but I don't believe it.

ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux], Rails 6.0.3.3

I have added a rails6 branch to the activerecord-advantage-adapter github project.

Ruby script:

jadams@Temp046317:~/code/ais-lims$ more ../testme.rb
require 'rubygems'
gem 'advantage'
gem "activerecord-advantage-adapter"
require "active_record"

ActiveRecord::Base.establish_connection(
  adapter: 'advantage',
  options: 'ServerType=Local|Remote; ReadOnly=True; CommType=TCP_IP; Compression=INTERNET',
  database: '//172.27.176.1:6262/c$/ads/db/'
)

class Discount < ActiveRecord::Base
  self.table_name = 'DISCOUNT'
  self.sequence_name = :autogenerated
end

puts Discount.all.inspect
puts Discount.count

jadams@Temp046317:~/code/ais-lims$ ruby ../testme.rb
#<ActiveRecord::Relation [#<Discount >, #<Discount >, #<Discount >, #<Discount >]>
4

Rails console:

jadams@Temp046317:~/code/ais-lims$ more config/database.yml
development:
  adapter: 'advantage'
  options: 'ServerType=Local|Remote; ReadOnly=True; CommType=TCP_IP; Compression=INTERNET'
  database: '//172.27.176.1:6262/c$/ads/db/'

jadams@Temp046317:~/code/ais-lims$ more app/models/discount.rb
class Discount < ApplicationRecord
  self.table_name = 'DISCOUNT'
  self.sequence_name = :autogenerated
end

jadams@Temp046317:~/code/ais-lims$ rails c
Running via Spring preloader in process 728
Loading development environment (Rails 6.0.3.3)
2.7.0 :001 > puts Discount.all.inspect
Traceback (most recent call last):
        1: from (irb):1
NoMethodError (undefined method `to_sym' for nil:NilClass)
2.7.0 :002 > puts Discount.count
Traceback (most recent call last):
        2: from (irb):1
        1: from (irb):2:in `rescue in irb_binding'
NoMethodError (undefined method `to_sym' for nil:NilClass)

Any hints on how to debug, or where to find the issue, I'd be grateful.

Jon


Solution

  • @rmlockerd and @ruby_object were both correct in helping to debug, but at the end of the day I'd just written the section of code in a way that didn't work.

    debugging was key