The user AstonJ experienced an error when running the discourse remap script to move a forum from name.com to forum.name.com. The error message indicated a duplicate key value violating a unique constraint, and the remap was only partially applied. After running the script again and performing some manual fixes, AstonJ asked for clarification on the script’s functionality and potential issues.
AstonJ noted that the script applies to the entire database, not just post content. jomaxro confirmed this and explained that the script affects various aspects of the database, including site settings, themes, and uploads.
After investigating the issue, AstonJ manually deleted a problematic TopicLink and reversed the remap, then reapplied it. The script completed successfully, and AstonJ reported the updated numbers of changes for each affected table. The cause of the increasing frequency of unique constraint errors remains unknown.
I just moved a forum from name.com to forum.name.com but it failed:
Error: ERROR: duplicate key value violates unique constraint “unique_post_links”
DETAIL: Key (topic_id, post_id, url)=(246, 813, http://forum.name.com) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.
So I ran it again (it failed again) then did rake posts:rebake and checked the forum to find I have some instances of forum.forum.name.com. (So then do discourse remap forum.forum.name.com forum.name.com and rake posts:rebake to try and fix it - with some success, I had to change some instances manually).
I have some questions:
Does discourse remap name.com forum.name.com only apply to post content? If not, is it just Site Settings I need to look through to find possible issues?
Should it be run in some sort of transaction? (If so, it didn’t appear to when it failed for me)
I’ve checked all site settings and they’re fine (as are themes) and I guess all the above were done - can you see anything that should have been done that wasn’t? Do you think it is safe to continue as is or do you think it needs to be redone from scratch?
Also any ideas why duplicate key value violates unique constraint errors are becoming more frequent on Discourse? I’ve noticed a few topics on this and I think this is the third time I’ve had such an issue myself.
Not from the output, no. We only output tables with changes. No way to know if a table not in the list because it of the error, or simply because there were no instances of name.com in the (not listed) table.
Any ideas what the numbers signify? Number of changes?
What is the recommended way forward now? Fix the unique constraint error then reverse (go from forum.name.com back to name.com, then back again) or do something else?
Edit: done
I entered the app and Rails console then deleted the TopicLink in question then went from forum.name.com back to name.com, then back again.