更改站点 URL 后运行 remap 时出错

我更改了 Discourse 站点的 URL,并正在按照 Change the domain name or rename your Discourse 中的说明进行操作。在尝试运行 remap 时,我反复遇到以下错误。它一直提示我重新运行脚本,但每次都会出现相同的错误。[1]

我不确定下一步该怎么做,如果能得到指导将不胜感激。提前感谢!:seedling:

root@digitallysovereign:/var/discourse# ./launcher enter app
x86_64 arch detected.
root@digitallysovereign-app:/var/www/discourse# discourse remap discourse.tobiaseigen.org digitallysovereign.org
Rewriting all occurrences of discourse.tobiaseigen.org to digitallysovereign.org
WILL RUN ON 'default' DB
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES): YES

Remapping tables on default...

ai_api_audit_logs=919
ai_secrets=1
backup_metadata=1
browser_pageview_events=3664
Error: ERROR:  duplicate key value violates unique constraint "idx_bprd_rollups_date_referrer_unique"
DETAIL:  Key (date, normalized_referrer)=(2026-07-01, digitallysovereign.org) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.
root@digitallysovereign-app:/var/www/discourse# discourse remap discourse.tobiaseigen.org digitallysovereign.org
Rewriting all occurrences of discourse.tobiaseigen.org to digitallysovereign.org
WILL RUN ON 'default' DB
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES): YES

Remapping tables on default...

Error: ERROR:  duplicate key value violates unique constraint "idx_bprd_rollups_date_referrer_unique"
DETAIL:  Key (date, normalized_referrer)=(2026-07-01, digitallysovereign.org) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.
root@digitallysovereign-app:/var/www/discourse# discourse remap discourse.tobiaseigen.org digitallysovereign.org
Rewriting all occurrences of discourse.tobiaseigen.org to digitallysovereign.org
WILL RUN ON 'default' DB
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES): YES

Remapping tables on default...

Error: ERROR:  duplicate key value violates unique constraint "idx_bprd_rollups_date_referrer_unique"
DETAIL:  Key (date, normalized_referrer)=(2026-07-01, digitallysovereign.org) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.

  1. 我知道“疯狂”的定义就是反复做同一件事却期待不同的结果!:rofl: ↩︎

看起来是 PostgreSQL 分析表中的约束冲突。你的数据库中已经包含了新域名在特定日期的记录,因此重映射工具可能会创建重复项,而 PostgreSQL 会拒绝这些重复项。

我建议仅删除新域名已有数据的特定日期范围内的旧域名记录,以保留历史数据并解除重映射工具的阻塞。但请先进行安全备份。

尝试以下操作:

cd /var/discourse
./launcher enter app
# 创建安全备份
discourse backup
# 进入数据库控制台
discourse db
/* 删除冲突的记录 */
DELETE FROM bprd_rollups 
WHERE normalized_referrer = 'discourse.tobiaseigen.org' 
AND date IN (
    SELECT date 
    FROM bprd_rollups 
    WHERE normalized_referrer = 'digitallysovereign.org'
);

/* 退出 PostgreSQL */
\q

然后再次运行重映射工具

discourse remap discourse.tobiaseigen.org digitallysovereign.org

然后使用 rebake_match rake 任务而不是完整重烘焙

# 仅重烘焙包含新域名字符串的帖子
rake posts:rebake_match["digitallysovereign.org"]