[Complete] [Paid] Migration script from NodeBB (redis) to Discourse

That is awesome! Hopefully that sweetens the pot for someone :smiley:


I poked around a bit at this to see what all I can figure out. I definitely don’t know enough about Ruby or the Discourse database structure to intelligently put this together.

I entertained the idea of doing a json export and was able to find a handy way to export posts, topics, and categories from some NodeBB functions.

var fs = require('fs');
var nconf = require('nconf');


nconf.argv().env().file({
  file: './config.json'
});

var db = require('./src/database');

function do_export(set, prefix) {
    db.getSortedSetRange(set, 0, -1, function(err, ids) {
          var keys = ids.map(function(id){ return prefix + id; });
          db.getObjects(keys, function(err, data) {
                fs.writeFile('db.export.' + set + '.json', JSON.stringify(data), function() {
                        console.log('Wrote '+set);
                });
          });
   });
}

db.init(function() {
  do_export('posts:pid', 'post:');  
  do_export('topics:tid', 'topic:');
  do_export('categories:cid', 'category:');
});

I noticed there was a json importer in discourse/script/import_scripts at main · discourse/discourse · GitHub, but I wasn’t sure how to properly name the json fields from NodeBB into the format for that import tool. The other missing piece was properly exporting and creating users in Discourse.

Here is some of the information I’ve been able to gather.

Example JSON output for categories

	{
		"cid": "1",
		"name": "Announcements",
		"description": "Announcements regarding our community",
		"icon": "fa-bullhorn",
		"bgColor": "#fda34b",
		"color": "#fff",
		"slug": "1/announcements",
		"parentCid": "0",
		"topic_count": "37",
		"post_count": "479",
		"disabled": "0",
		"order": "1",
		"link": "",
		"numRecentReplies": "1",
		"class": "col-md-3 col-xs-6",
		"imageClass": "cover",
		"descriptionParsed": "Announcements regarding our community",
		"undefined": "on"
	}

Example JSON output for topics

	{
		"tid": "94",
		"uid": "1",
		"cid": "1",
		"mainPid": "1741",
		"title": "DNS Issues",
		"slug": "94/dns-issues",
		"timestamp": "1466967610616",
		"lastposttime": "1466967681716",
		"postcount": "2",
		"viewcount": "363",
		"locked": "0",
		"deleted": "0",
		"pinned": "0",
		"teaserPid": "1742",
		"upvotes": "0",
		"downvotes": "0"
	}

Example JSON output for posts

	{
		"timestamp": "1466967610620",
		"tid": "94",
		"deleted": "0",
		"edited": "0",
		"content": "In my attempts to resolve some issues with email activations, I made some changes to DNS. Unfortunately, the switch did cause a refresh of DNS and is making the site unresolvable by some. Please keep trying. A reboot of your router, modem and PC may fix it as well to help out! Sorry again for breaking things. Good old growing pains :D",
		"replies": "1",
		"editor": "",
		"uid": "1",
		"pid": "1741"
	}

Example of the user data in redis (NodeBB)
NOTE: I can’t find an easy way to export data out from redis into JSON (I’m ignorant of redis as well), so I manually formatted this in JSON

	{
		"password": "salted_hash",
		"birthday": "mm/dd/yyyy",
		"reputation": "2623",
		"joindate": "1466804324458",
		"fullname": "Geran Smith",
		"signature": "(Shh, I am Geran)\nSteam Group -- http://steamcommunity.com/groups/gaming_exodus\nMy gaming profiles -- https://gamingexodus.com/post/17901",
		"banned": "0",
		"picture": "https://www.gravatar.com/avatar/9e2032064fd490a386fffd19b98feace?size=192",
		"uid": "1",
		"lastposttime": "1524180627000",
		"cover:position": "50.0307% 54.4151%",
		"followingCount": "3",
		"website": "https://gamingexodus.com",
		"passwordExpiry": "0",
		"postcount": "1966",
		"uploadedpicture": "",
		"userslug": "teh-g",
		"email:confirmed": "1",
		"lastonline": "1524190227557",
		"email": "user@domain.xyz",
		"username": "teh g",
		"flags": "0",
		"aboutme": "",
		"cover:url": "https://i.imgur.com/XTMkINp.jpg",
		"profileviews": "1712",
		"rss_token": "token_string",
		"groupTitle": "administrators",
		"followerCount": "25",
		"topiccount": "166",
		"status": "online",
		"location": "USA"
	}

Hopefully my weirdly obsessive research helps someone to take the bounty!

3 Likes