# Migrating embedded topics from topicId to automatic topic creation

**URL:** https://meta.discourse.org/t/migrating-embedded-topics-from-topicid-to-automatic-topic-creation/284553
**Category:** Migration
**Tags:** embedding
**Created:** [November 6, 2023, 11:29am UTC](https://meta.discourse.org/t/migrating-embedded-topics-from-topicid-to-automatic-topic-creation/284553 "2023-11-06T11:29:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![n1bff](https://avatars.discourse-cdn.com/v4/letter/n/e95f7d/32.png) [@n1bff](https://meta.discourse.org/u/n1bff)
#### Post date: [November 6, 2023, 11:29am UTC](https://meta.discourse.org/t/migrating-embedded-topics-from-topicid-to-automatic-topic-creation/284553/1 "2023-11-06T11:29:15Z")

</div>

The environment: I have a Discourse forum and a website. The website has pages. The pages use embedded Discourse topics for commenting.

As part of a migration process I am currently using a hard-coded mapping of “webpage url” to “Discourse topic id” and use server-side code on the webpages to embed the appropriate Discourse topic.

This works well for all existing webpages because I migrated previous comments into Discourse topics.

For new webpages it would be too much overhead to a) create a new topic and b) continue to track the new mappings between webpages and topics. So I would like to switch to Discourse’s own logic for creating topics on-demand and not specify the existing topic IDs on the webpages anymore.

I assume that Discourse has its own mapping table to know which topic to serve if a request for an embedded comment thread comes in.

Is that the case and can I manually insert my existing mappings there, then switch my webpages to use that functionality?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [November 6, 2023, 4:23pm UTC](https://meta.discourse.org/t/migrating-embedded-topics-from-topicid-to-automatic-topic-creation/284553/2 "2023-11-06T16:23:59Z")

</div>

So you want to [Embed Discourse comments on another website via Javascript](https://meta.discourse.org/t/embed-discourse-comments-on-another-website-via-javascript/31963)?

---

<div class="post-metadata">

### Author: ![n1bff](https://avatars.discourse-cdn.com/v4/letter/n/e95f7d/32.png) [@n1bff](https://meta.discourse.org/u/n1bff)
#### Post date: [November 6, 2023, 4:48pm UTC](https://meta.discourse.org/t/migrating-embedded-topics-from-topicid-to-automatic-topic-creation/284553/3 "2023-11-06T16:48:23Z")

</div>

That is what I already do and where I want to change the configuration.

Currently I use [Embed Discourse comments on another website via Javascript](https://meta.discourse.org/t/embed-discourse-comments-on-another-website-via-javascript/31963#alternate-configuration-linking-to-existing-topics-6) (“Configuring Discourse for Embedding (simple setup)”)

And I want to change to the standard [Embed Discourse comments on another website via Javascript](https://meta.discourse.org/t/embed-discourse-comments-on-another-website-via-javascript/31963#configuring-discourse-for-embedding-simple-setup-2) (“(Alternate Configuration) Linking to existing topics”)

---

<div class="post-metadata">

### Author: ![n1bff](https://avatars.discourse-cdn.com/v4/letter/n/e95f7d/32.png) [@n1bff](https://meta.discourse.org/u/n1bff)
#### Post date: [February 23, 2024, 9:49pm UTC](https://meta.discourse.org/t/migrating-embedded-topics-from-topicid-to-automatic-topic-creation/284553/4 "2024-02-23T21:49:39Z")

</div>

I added a simple if switch to my website that uses a stored `topicId` if available and the page’s `discourseEmbedUrl` otherwise.

Sadly I had a bad URL for some pages and now I have bad thread references between the pages and the threads. I found the table `topic_embeds`, that seems to be it. Can I safely delete from that table and re-visit the pages to regenerate threads? Or do I need to clean up some related rows elsewhere?
