Rebake fails when changing the subdomain name only

AI-generated summary

YaserAlnajjar encountered a duplicate key value error while running discourse remap to change the domain from forums.coretabs.net to discourse.coretabs.net, due to existing entries in the incoming_domains table. sam advised manually updating the conflicting records. YaserAlnajjar followed sam’s suggestion to rename the domain in incoming_domains via rails c, omitting the word from in the SQL command. After rerunning the remap, a new error occurred on the unique_post_links constraint in the topic_links table. YaserAlnajjar resolved this by using REPLACE in SQL to update URLs in topic_links to point to a temporary domain (discourse-old.coretabs.net), allowing the remap to complete successfully. The fix introduced minor data inconsistencies but restored functionality. YaserAlnajjar thanked sam for the guidance.

Hi

I recently copied the /shared database folder from our production to staging server (to make both environments match).

I realized the links are pointing to the previous domain, so I followed this guide

When running this command inside the container:

discourse remap forums.coretabs.net discourse.coretabs.net

I get a duplicate key value error:

Rewriting all occurences of forums.coretabs.net to discourse.coretabs.net
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES)
YES
Error: ERROR:  duplicate key value violates unique constraint "index_incoming_domains_on_name_and_https_and_port"
DETAIL:  Key (name, https, port)=(discourse.coretabs.net, t, 443) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.

Yeah I don’t think we have conflict handling built in and you have incoming links for both domains.

You are going to need to manually delete stuff from the problem table prior to running this task.

Thanks Sam for the fast reply!

Could you please point me to where I can manipulate the problematic table?

rails c
DB.exec "update from incoming_domains set name='discourse-old.coretabs.net' where name = 'discourse.coretabs.net'"

Is likely what you want it will lead to a minor data inconsistency but at least the remap will probably work.

So here is what I did:

  1. I run the command you pointed out (without from :grin:)

  2. Run the rebake again, now it stopped here:

Rewriting all occurences of forums.coretabs.net to discourse.coretabs.net
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES)
YES
incoming_domains=1
incoming_referers=3
invites=1
javascript_caches=1
post_revisions=509
posts=84
single_sign_on_records=1099
theme_fields=4
topic_custom_fields=4
Error: ERROR:  duplicate key value violates unique constraint "unique_post_links"
DETAIL:  Key (topic_id, post_id, url)=(69, 212, https://discourse.coretabs.net/t/topic/365) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.
  1. Googled "unique_post_links" and found that its table is called topic_links from the schema.sql

  2. This time links are partial so I used a replace query:

DB.exec "update topic_links set url=REPLACE(url, 'discourse.coretabs.net', 'discourse-old.coretabs.net')"
  1. Run the rebake again.

Works like a charm, thanks Sam :rose: