In a discussion about importing Snitz forum data into Discourse using TinyTDS, user Kevin_McKinney initially struggled with dependency issues between Ruby 2.3.0, TinyTDS, and the Docker container’s Ruby 2.0.0. Unable to develop a Ruby script due to comfort levels with Linux and Rails, Kevin_McKinney resorted to a manual CSV export workaround. gerhard provided a solution by installing freetds-dev and updating the Gemfile with gem 'tiny_tds', followed by a specific bundle install command. Kevin_McKinney confirmed this method worked, noting that the missing freetds-dev installation was the likely cause of their previous errors. They expressed satisfaction at moving to a direct database query method. Finally, gpetrov asked if Kevin_McKinney could share the resulting script for future Snitz imports.
I’m importing from a Snitz forum, which doesn’t have an existing import script. I’m not a Ruby developer, so I’m hacking things together as I go.
Snitz uses an MS SQL Server backend, and when I look up “Ruby MS SQL Server” everything seems to point to TinyTDS. I’m able to do that in Ruby 2.3.0, but when I try it in my script I run into dependency issues. It seems like the Docker container is running Ruby 2.0.0 and I’m not able to get TinyTDS to work because of dependency issues with activerecord and other gems (I think? Again, not really comfortable with Ruby or Rails, or Linux for that matter).
So I’m currently exporting things to a CSV file and then importing from there as a workaround, but I was curious if there was something I’m just missing in terms of getting an import script to connect to SQL. There’s probably a way to connect using something other than TinyTDS but I’m way out of my depth already and I was afraid of breaking the entire site (again… I restored my VM several times during this process because I hosed things while trying to bend things to my will).
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!