Hi,
I tried to change a discourse domain name, following Change the domain name or rename your Discourse. Things looked right until I launched the command
discourse remap talk.foo.com talk.bar.com
I got the following:
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.
It seemed it looked like to the error reported here, but was slightly different. I guess the bug is related to the fact that the new domain has been discussed on the forum.
To overcome it, I was unable to launch something like db:exec
to force db commands via rake
. So I did it directly via postgres:
- connect the dababase:
# cd /var/discourse/
# ./launcher enter app
# su - postgres
$ psql
postgres=# \c discourse
- try to directly replace url in the table
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.
- on error : force a replacement that don’t break unicity, e.g.
forum.plop.fr/
:
discourse=# update topic_links set url=REPLACE(url, 'plop.domain.fr', 'forum.plop.fr/') where topic_id=274;
- repeat 3. until 2. finishes without error. Then quit pg.
discourse=# update topic_links set url=REPLACE(url, 'plop.domain.fr', 'forum.plop.fr');
UPDATE 1349
discourse=#
\q
- relaunch the remap and the rebake:
$ exit
# discourse remap plop.domain.fr forum.plop.fr
- Manually check and correct the problematic topics (which content may be inconsistent), by visiting
forum.plop.fr/t/topic/274
and others.