Troubles executing import/migration scripts

I have successfully migrated a forum to Disourcse with a custom script before, but now when I execute it again, I get the following import error:

/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client': We could not find your database: discourse. Which can be found in the database configuration file located at config/database.yml. (ActiveRecord::NoDatabaseError)

To resolve this issue:

- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

        bin/rails db:create

The following import in my script fails:

require File.expand_path(File.dirname(__FILE__) + "/base.rb")

I execute the script with

./launcher enter app
cd /var/www/discourse
bundle exec ruby script/import_scripts/avatar.rb

I don’t really understand the error though: I can access the database through sudo -u postgres psql discourse, validating that the database “discourse” does exist. Also, the website is running fine. When I open rails c I can also access the data.

Can you give me some pointers what’s messed up there?

Discourse can’t find its database. So you need to fix that. Was this a standard install or a development install? Have a look at the appropriate guide and make discourse work as the first step.

Standard install, following discourse/INSTALL-cloud.md at main · discourse/discourse · GitHub

The only thing I did (that I can think of now) since it was working last time was reverting to backups.

What confuses me about the error is that everything else works. The site works perfectly fine. Only the import script fails.

And you’re running they script inside the container?

Yes, I use ./launcher enter app and I have only one configuration (app).

Oh. Sorry. You said all of that in the OP;I didn’t read very well!

I can’t think of an explanation. Maybe reboot?

I did reboot and it didn’t fix the issue. I now also encounter the same issue on my local machine (local docker)… which makes me think that somehow I run the command somehow incorrectly…

And thank you – I celebrate the swiftness of your responses and the support!

Yes, now I got it. I executed the script as root, but not as user discourse:

./launcher enter app
cd /var/www/discourse
su discourse
bundle exec ruby script/import_scripts/import.rb

Thanks for the support @pfaffman <3

3 Likes

Hmm. Perhaps something had changed, as I’m site that I’ve not been running import scripts as used discourse. Good work!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.