Migrating from bbPress WordPress plugin to Discourse

import

(Vinoth Kannan) #1

I recently did a bbPress database migration successfully using Discourse’s inbuilt migration script. Now I’m going to share it as a step-by-step tutorial.

Note: This tutorial is for the bbPress plugin, not the legacy standalone version of bbPress.

What data can be imported?

  • Users
  • Categories
  • Topics
  • Posts

Before starting the migration set a development environment on your machine (or inside a virtual machine) and run the import there instead of inside the docker container. When I tried it inside docker container I got peer authentication failed issue. So I strongly recommending you that you use a development machine. See the OS X or Ubuntu installation guide for development.

I used Ubuntu 16.04 LTS amd64 xenial image. I recommending using Ruby version 2.3.0 or above (at least 2.0.0). Because I had some compatability issues when installing mysql2 with older versions of Ruby.

To check Ruby version enter the command below

ruby -v

Now we need to install the libmysqlclient-dev dependency in order to be able to use the mysql2 gem.

sudo apt-get install libmysqlclient-dev

After the successful installation go to your Discourse installation path and open bbPress import script file to edit.

cd /var/discourse
sudo nano script/import_scripts/bbpress.rb

In this file you can find the mysql database connection code below

    @client = Mysql2::Client.new(
      host: "localhost",
      username: "root",
      database: BB_PRESS_DB,
    )

By default the database host is localhost and username is root.

If you are migrating your database from localhost you don’t need to change these settings (in most cases). You have to change the database name only.

Database name is retrieved from ENV variable. You can check it in top of the ruby file. So you can set it in ~/discourse/.env file or just edit the name database attribute like below. I prefer second method :stuck_out_tongue:

    @client = Mysql2::Client.new(
      host: "localhost",
      username: "root",
      database: "my_bbpress",
    )

If you are migrating your database from external server then you have to add password attribute to database settings. I am going to simply add raw password in the Ruby file directly. You may add it in .env file and use it here like database name. So after password inclusion your mysql database setting should look like below.

    @client = Mysql2::Client.new(
      host: "REMOTE_HOST_NAME",
      username: "DB_USERNAME",
      password: "MY_SECURE_PASSWORD",
      database: "DB_NAME",
    )

Now save the file and exit. It’s time to run migration script :open_mouth:

Run the command below in your discourse installation path.

IMPORT=1 bundle && IMPORT=1 bundle exec ruby script/import_scripts/bbpress.rb

Congratulations! Your database successfully migrated from bbPress to Discourse :clap: :wave: :boom:

Now take a backup from admin page /admin/backups and import it in your live Discourse website.


After you moved your bbPress forum to Discourse if you are still going to use your WordPress website as primary site and you’d like to connect it with Discourse then install Discourse’s official WordPress plugin.


[Paid] Migrating old wordpress comments and users to Discourse
How to setup discource forum to my website
Import_scripts are missing
How to export WordPress users in discourse?
(Kellbot) #3

Just wanted to thank you for providing this step-by-step guide. We migrated our site from bbpress to Discourse with minimal headache thanks to you. Since we’re running multisite wordpress there were a few tweaks to make to the importer, but other than that it went very smoothly. Thanks!


(Vinoth Kannan) #4

If you can share your tweaks then it will be helpful to other multisite owners.


(Kellbot) #5

Admittedly I didn’t take very good notes, and have since killed the VM it
was on (sorry!) but the basic gist is that if your bbpress install is not
on the primary site of the Multisite setup you’ll need to a) set the
environmental variable for BBPRESS_PREFIX to include your site’s ID number
(e.g. wp_6_ ) and then edit the migration script to use wp_users rather
than #{BBPRESS_PREFIX} for the Users sql. This is because on Multisite
installations the wp_users table is shared across sites and then each site
has its own tables for posts, postmeta, etc.


(Vinoth Kannan) #6

thanks for the details :thumbsup:


#7

I recently posted on how to import bbpress into discourse


(Erlend Sogge Heggen) #8

Great job on the tutorial! But it’s confusing to have two different guides on this. Do they serve different purposes? Otherwise we should figure out how to merge them.


#9

That guide is about how to import bbpress inside of a development environment, mine is how to import bbpress using the docker container. It’s just 2 different ways to go. I’d recommend importing via docker container since it doesn’t ask for the additional step of setting up a development environment, which can be cumbersome.