This seems to be working. If I understand what you’re doing above, I think the only thing I didn’t do was apt-get install freetds-dev, and then I only did 'bundle install --no-deployment'.
That’s a neat trick to write to a file without installing an editor with echo. I of course had to install nano in order to edit the Gemfile.
I’m going to keep going down this path, because it would be a lot nicer to query the DB directly than this manual step of creating CSV files has been. Thanks!