导入/迁移脚本执行困难

我之前成功地使用自定义脚本将论坛迁移到了 Discourse,但现在再次执行时,出现了以下导入错误:

/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

我的脚本中的以下导入失败:

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

我使用以下命令执行脚本:

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

但我不太明白这个错误:我可以通过 sudo -u postgres psql discourse 访问数据库,这证实了“discourse”数据库确实存在。而且,网站运行正常。当我打开 rails c 时,我也可以访问数据。

你能给我一些关于哪里出错了的提示吗?

Discourse 找不到其数据库。因此,您需要解决此问题。这是标准安装还是开发安装?请查看相应的指南,并将 Discourse 作为第一步使其正常工作。

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

我唯一能想到的自上次工作以来我做的事情就是恢复备份。

让我感到困惑的是,其他一切都正常工作。网站运行得非常好。只有导入脚本失败了。

并且你在容器内运行脚本吗?

是的,我使用 ./launcher enter app,并且只有一个配置(app)。

哦。抱歉。你在 OP 中说了所有这些;我没怎么看!

我想不出什么解释。重启试试?

我重启了,但问题没有解决。现在我的本地机器(本地 Docker)上也遇到了同样的问题……这让我觉得是我以某种方式错误地运行了命令……

谢谢——我赞赏您迅速的回复和支持!

是的,我现在明白了。我以 root 用户身份执行了脚本,而不是以 discourse 用户身份执行:

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

感谢 @pfaffman 的支持 <3

3 个赞

嗯。也许有些东西变了,因为我确定我没有像以前那样运行导入脚本。干得好!

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