How to migrate to Liveblocks Comments
To migrate your threads, comments, and reactions to Liveblocks Comments, you can create a migration script using our Node.js methods or REST API. This guide will take you through all the Liveblocks features required to create a migration script in Node.js. Note that each Node.js method also has an equivalent REST API which could be used instead.
Creating rooms
The first step is to create the multiplayer room where the comments are stored. This is equivalent to a document in your project. Make sure to read the sections on permissions under access tokens or ID tokens to fully understand setting up your room.
Create a room using
liveblocks.createRoom
or the
Create Room API, and set
permissions if you’re using ID tokens.
Creating threads
Next up is creating threads in the room. Before starting, make sure you
understand the
concepts behind Comments. When a
thread is created, the first comment is also created, and you can do this with
liveblocks.createThread
or the
Create Thread API.
Read under
liveblocks.createThread
to learn how to create a Comment body, and check in
GitHub
for information about each comment body element.
Adding further comments
To add more comments to the new thread, use
liveblocks.createComment
or the
Create Comment API.
We’re just sharing a simple code snippet below, but of course, we recommend you
use a loop.
Adding reactions
To add reactions to each comment, use
liveblocks.addCommentReaction
or the
Add Comment Reaction API.
Migrating users
There’s no need to migrate users to Comments, as the only user information
Liveblocks stores
is each user’s ID.
Other user info is retrieved in-app by Comments with
resolveUserInfo
.
Putting it together
To create a migration script, put everything together and loop through all the
functions we’ve listed above. Below is an example of a migration script, though
you’ll need to make changes based on the format of the comment system you’re
migrating from. oldDocumentId
and oldDocumentThreads
represent your current
data.