Hi everyone,
As a self-hoster, I recently caught the “digital OCD” bug. I had some deleted categories and tags from my early testing days, and I really wanted to reclaim those clean, single-digit IDs (like Category ID 2 and Tag ID 3) instead of leaving gaps in my database.
I know the UI doesn’t support this, so I went into the Rails console (./launcher enter app → rails c) to manually piece things back together. Everything looks and works perfectly on the frontend right now, but I am curious if the database experts here see any hidden dangers or long-term landmines in doing this.
Here is the exact, detailed workflow I ran:
1. Recreating the deleted Category using its old ID with full attributes: Instead of just forcing an ID, I provided the essential attributes so the record is complete.
Ruby
Category.create!(
id: 2,
name: "Site Feedback",
color: "0088CC",
text_color: "FFFFFF",
user_id: -1 # System user
)
2. Recovering the original topic and linking it as the category description:
Ruby
Topic.with_deleted.find(1).recover!
Category.find(2).update!(topic_id: 1)
3. Cleaning up the topic subtype (restoring to vanilla default): I checked other default categories and noticed their description topics just use nil, so I reverted it to the factory state.
Ruby
Topic.find(1).update!(subtype: nil)
4. Bulk-recreating old tags to fill the ID gaps:
Ruby
Tag.create!([
{ id: 3, name: "private-school" },
{ id: 7, name: "tennis" }
])
My main question: I completely understand there is no practical need to do this other than satisfying my own OCD. However, strictly from a structural standpoint, do basic ActiveRecord methods like .update! and .create! safely trigger all the necessary Discourse callbacks (Search indexing, Redis cache updates, Sidekiq jobs, routing, etc.)? Or did I accidentally bypass some crucial internal logic that might break a future schema migration?
Thanks for satisfying my curiosity!