Hello. I don’t know if it’s possible, and if it is I googled a lot and did not find anything about this, but I would like to sort all the replies of all the topics of my forum by the created date.
I’ve been working on a migration of data from an old forum to a brand new Discourse one. To do that, I am recreating the topics and replies via API so that I can send them to Discourse on the date the reply was created initially. That has been working just fine as when I go to the created replies on Discourse I can see that the original date is over there.
But even though all the replies are with the original date, they are sorted by the order they were created on the API. I don’t know if this is a bug or meant to be or if there is any way to sort them by the date I set on the API POST call, but if so I’d like some help on this topic. Cheers guys.
Posts are displayed in the order in which they are created. So you’d need to have your API script (that you really don’t want to use) create them in the proper order.
Hmmm, thanks for the reply. I did think about using a script a while ago but since Discourse has a lot of table relationships I decided to go through the API. But is there any way to create a script that will insert data in one table and then Discourse handles the rest of the relationship? That might make things easier for me.
But I mean, the migration via API has been working so far. I wonder what is the point of being able to send a created_at attribute on the endpoint to create posts if Discourse won’t show it sorted by it anyway… Shouldn’t this be a feature request?
No, because the way to solve your problem is to use one of the dozens of examples that I linked to is the way to solve your problem. I promise it will be much, much easier. I wrote several import scripts before I really even learned ruby.
Even if you wanted to use the API, you still need to create the posts in the created_at order. There are ways to sort them in a plugin v(or maybe theme component?) , but you really don’t want to do that.
I see. I will keep following my idea, just wanted to know regarding the created_at attribute on the POST call when creating a post - which is, as it seems, useless, if the posts can’t be sorted by it. Thanks anyway.
Just FYI, the reason things don’t just sort by created date is because things are designed to support moving posts from one topic to another, and in that scenario, it’s proven less desireable to have posts get “mixed up” if the dates overlap.
Here’s an earlier discussion about that:
On the topic of how best to approach a migration, I agree w/ Jay. You’re likely better off following prior art here. While not a web API, the existing scripts rely on a lower level “migration API” of sorts with this in mind.
The web API is largely designed as an API for the front-end Discourse app. While it’s successfully used for various integrations, it is optimized for it’s primary purpose.