Moving posts into an existing topic doesn't keep chronology

I had a need to use this for some email threads that were split into separate topics during import so I thought I would elaborate on this in case anyone else also needs it. You’ll need to be able to access the command line on the server running your Discourse instance.

Start by moving all the desired posts into the target topic, then get the topic ID. In the address bar you might see something like the following, where the topic ID is 24855:
/t/topic-slug/24855/9

On your server, enter the Discourse app with the following commands. You may need to clear some space if you have less than 5GB available.

cd /var/discourse
./launcher enter app

If that is successful, you can then reorder the posts by their timestamps with the following command, replacing the topic ID as appropriate.

rake posts:reorder_posts[24855]
5 Likes