您好,
我尝试按照 Change the domain name or rename your Discourse 的说明更改 discourse 的域名。在执行以下命令时,一切看起来都正常:
discourse remap talk.foo.com talk.bar.com
但我遇到了以下错误:
root@plop:/var/www/discourse# discourse remap plop.domain.fr forum.plop.fr
Rewriting all occurrences of plop.domain.fr to forum.plop.fr
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES)
YES
backup_metadata=1
email_logs=991
javascript_caches=1
post_revisions=126
post_search_data=20
posts=782
stylesheet_cache=446
theme_settings=1
Error: ERROR: duplicate key value violates unique constraint "unique_post_links"
DETAIL: Key (topic_id, post_id, url)=(274, 455, http://forum.plop.fr) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.
这似乎与此处报告的错误类似:here,但略有不同。我猜测这个 bug 可能与新域名已经在论坛上被讨论过有关。
为了解决这个问题,我无法通过 rake 运行类似 db:exec 的命令来强制执行数据库命令。所以我直接通过 postgres 操作:
- 连接数据库:
# cd /var/discourse/
# ./launcher enter app
# su - postgres
$ psql
postgres=# \c discourse
- 尝试直接替换表中的 URL:
discourse=# update topic_links set url=REPLACE(url, 'plop.domain.fr', 'forum.plop.fr');
ERROR: duplicate key value violates unique constraint "unique_post_links"
DETAIL: Key (topic_id, post_id, url)=(274, 455, http://forum.plop.fr) already exists.
- 出错时:强制执行一个不破坏唯一性的替换,例如
forum.plop.fr/:
discourse=# update topic_links set url=REPLACE(url, 'plop.domain.fr', 'forum.plop.fr/') where topic_id=274;
- 重复步骤 3,直到步骤 2 成功执行。然后退出 pg。
discourse=# update topic_links set url=REPLACE(url, 'plop.domain.fr', 'forum.plop.fr');
UPDATE 1349
discourse=#
\q
- 重新启动 remap 和 rebake:
$ exit
# discourse remap plop.domain.fr forum.plop.fr
- 手动检查并更正有问题的主题(内容可能不一致),方法是访问
forum.plop.fr/t/topic/274等。