# Migrate specific Xenforo content

**URL:** https://meta.discourse.org/t/migrate-specific-xenforo-content/291527
**Category:** Migration
**Tags:** xenforo
**Created:** [January 13, 2024, 4:27pm UTC](https://meta.discourse.org/t/migrate-specific-xenforo-content/291527 "2024-01-13T16:27:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [January 13, 2024, 4:27pm UTC](https://meta.discourse.org/t/migrate-specific-xenforo-content/291527/1 "2024-01-13T16:27:48Z")

</div>

Hi Discourse comm,

I have a lot of content from an old xenforo database that I want to import, but I don’t want to do a few things:

Ideally, I only want to import the threads and the first post from each thread, I also want to re-assign the thread starter to a different discourse forum/user account that I’ve already created. is this possible in an easy-enough way?

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [January 13, 2024, 4:36pm UTC](https://meta.discourse.org/t/migrate-specific-xenforo-content/291527/2 "2024-01-13T16:36:45Z")

</div>

> [@Ventrilo](#):
>
> import the threads and the first post from each thread

just modify the SQL in the import script

```plaintext
        SELECT p.post_id id,
               t.thread_id topic_id,
               #{@prefix_as_category ? "t.prefix_id" : "t.node_id"} category_id,
               t.title title,
               t.first_post_id first_post_id,
               t.view_count,
               p.user_id user_id,
               p.message raw,
               p.post_date created_at
        FROM #{TABLE_PREFIX}post p,
             #{TABLE_PREFIX}thread t
        WHERE p.thread_id = t.thread_id
        AND p.message_state = 'visible'
        AND t.discussion_state = 'visible'
        ORDER BY p.post_date
        LIMIT #{BATCH_SIZE}" # needs OFFSET

```

add `AND p.post_id = t.first_post_id` to the `WHERE` clause

> [@Ventrilo](#):
>
> I also want to re-assign the thread starter to a different discourse forum/user account that I’ve already created

Change

`mapped[:user_id] = user_id_from_imported_user_id(m["user_id"]) || -1`

to

`mapped[:user_id] = xxx`

where `xxx` is the Discourse user ID you want to assign the topics to.

---

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [January 13, 2024, 4:43pm UTC](https://meta.discourse.org/t/migrate-specific-xenforo-content/291527/3 "2024-01-13T16:43:50Z")

</div>

@RGJ thanks for the quick response, you couldn’t happen to show me the SQL statement with the correct4 edit, ive tried including the `AND p.post_id = t.first_post_id` to the where clause but im getting SQL validation errors on the statment

oh and where is this import script?! thanks for spoonfeeding me i appreciate it

---

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [January 13, 2024, 6:42pm UTC](https://meta.discourse.org/t/migrate-specific-xenforo-content/291527/4 "2024-01-13T18:42:46Z")

</div>

![image](https://global.discourse-cdn.com/meta/original/4X/d/1/c/d1c9e351e5124c74c046aaaf879428e7f5bbac6e.png)

Spent hours trying and got no where really, is there no paid support with discourse for this type of thing?

---

<div class="post-metadata">

### Author: ![Firepup650](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/firepup650/32/465200_2.png) [@Firepup650](https://meta.discourse.org/u/Firepup650)
#### Post date: [January 13, 2024, 6:44pm UTC](https://meta.discourse.org/t/migrate-specific-xenforo-content/291527/5 "2024-01-13T18:44:05Z")

</div>

> [@Ventrilo](#):
>
> is there no paid support with discourse for this type of thing?

You could probably make a topic in #Marketplace.

---

<div class="post-metadata">

### Author: ![Ventrilo](https://avatars.discourse-cdn.com/v4/letter/v/b487fb/32.png) [@Ventrilo](https://meta.discourse.org/u/Ventrilo)
#### Post date: [January 13, 2024, 8:17pm UTC](https://meta.discourse.org/t/migrate-specific-xenforo-content/291527/6 "2024-01-13T20:17:24Z")

</div>

So I’m getting this error:

cannot load such file – /var/discourse/config/environment

and in base.rb line 16 this exists:

require\_relative “../../config/environment”

nothing in any import/migraton tutorial mentions the fact this doesn’t exist
