Import data from Phorum

Hi,
I am trying to import data from Phorum database. I have filled db data to the phorum.rb script (mysql name, pass, db name) and tried to run the script with: ruby script/import_scripts/phorum.rb

but it failed with this error:

/var/discourse/script/import_scripts/base.rb:14:in `require_relative': cannot load such file --
/var/discourse/config/environment (LoadError)
from /var/discourse/script/import_scripts/base.rb:14:in `<top (required)>'
from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
from script/import_scripts/phorum.rb:3:in `<main>'

Have you any idea what am I doing wrong?

Thanks so much!

Have you installed the mysql2 gem? It’s not in our Gemfile since we use postgresql. You can install with gem install mysql2.

1 Like

Yup, I have installed that (it was first thing I have done, import script showed different error and it was clear that mysql2 was missing).

Ok, pinging @techAPJ since he wrote it. He might be able to help you out.

2 Likes

Are you running the import script on production server? If yes, can you confirm you’re running import script like this:

RAILS_ENV=production bundle exec ruby script/import_scripts/phorum.rb

I am not sure if it’s production server (I’ve followed Discourse installation guide here) and if I try to run command you’ve mentioned it ends with: Could not locate Gemfile (even if I try it from directory with phorum.rb).

Hey @techAPJ , sorry for pinging you. I’d be happy if you could point at what I am doing wrong. Thank you very much!

Looks like you’re trying to run the importer inside the Docker container. This should work:

cd /var/www/discourse
su discourse -c 'bundle exec ruby script/import_scripts/phorum.rb'

No, the result is same:
Could not locate Gemfile

Command to start was: su root -c 'bundle exec ruby script/import_scripts/phorum.rb' from /var/discourse. I have Vagrantfile there but really no Gemfile.

Did you delete the Gemfile? Try running

cd /var/www/discourse
git reset HEAD --hard

or recreate your Docker container.

1 Like

I tried:
git reset HEAD --hard
git pull
./launcher rebuild app
bundle exec ruby script/import_scripts/phorum.rb as root

Still no Gemfile. I forgot to mention that I always have to modify launcher, because it detects uppercase characters, spaces or special characters in app, so I just comment out exit 1 line.

Ok, some progress at least. I’ve manually downloaded Gemfile and did bundle install but right now it’s ending because of:
script/import_scripts/phorum.rb:1:inrequire’: cannot load such file – mysql2`

(even if mysql2 gem is installed)

You need to enter the Docker container:

./launcher enter app

Then install the mysql2 gem…

apt-get update && apt-get install -y nano libmysqlclient-dev
cd /var/www/discourse
echo "gem 'mysql2'" >> Gemfile
su discourse -c 'bundle install --no-deployment --without test --without development --path vendor/bundle'

… configure the import script

nano script/import_scripts/phorum.rb

and execute the importer

su discourse -c 'bundle exec ruby script/import_scripts/phorum.rb'

It ended with:

/var/discourse/script/import_scripts/base.rb:14:in `require_relative': cannot load such file -- /var/discourse/config/environment (LoadError)
    from /var/discourse/script/import_scripts/base.rb:14:in `<top (required)>'
    from script/import_scripts/phorum.rb:3:in `require'
    from script/import_scripts/phorum.rb:3:in `<main>'

If I compare directories on github and in /var/discourse I have missing a lot of them (I don’t know how that’s possible). Shouldn’t I try to remove entire /var/discourse and download it again?

Sincerely, it would be much easier for you to set up a development environment and run the import there rather than in a production server.

2 Likes

I finally managed to find time to set up development installation and import worked perfectly.

Thanks!