migration
The blocklet server migration command migrates the Blocklet Server's database from one dialect to another, such as from SQLite to PostgreSQL. This is typically used when scaling up a Blocklet Server instance for a production environment that requires a more robust database backend.
Usage#
blocklet server migration --dialect <dialect>Options#
Option | Description |
|---|---|
| Required. Specifies the target database dialect. Supported values: |
Prerequisites#
Before running the migration, ensure the following conditions are met:
- Initialize Database: The Blocklet Server must have been started at least once to ensure the initial database and blocklet metadata exist.
- Stop Server: The server should be stopped before initiating the migration to prevent data corruption.
- Configure Target DB: If migrating to PostgreSQL, the
ABT_NODE_POSTGRES_URLenvironment variable must be set to your valid PostgreSQL connection string.
Migration Process#
The command automates reading all existing blocklet configurations from the source database and then applies the necessary schema migrations to the new target database. This ensures all your existing data is transferred correctly.
Example: Migrating to PostgreSQL#
Here is a step-by-step guide to migrate your Blocklet Server instance from the default SQLite to PostgreSQL.
- Stop the Server
If your Blocklet Server is running, stop it first.blocklet server stop - Configure PostgreSQL Connection
Set theABT_NODE_POSTGRES_URLenvironment variable in your shell. This tells the CLI how to connect to your PostgreSQL database.export ABT_NODE_POSTGRES_URL="postgresql://user:password@localhost:5432/my_blocklet_db" - Run the Migration
Execute the migration command, specifyingpostgresas the target dialect.blocklet server migration --dialect postgresYou will see output logs indicating the progress.info: Getting blocklets...
info: Running migrations for core
info: create table "roles"
...
success: Migration postgres completed
info: Please start server, will use Postgres database: blocklet server start - Restart the Server
Start your Blocklet Server again. It will now automatically connect to and use the PostgreSQL database you configured.blocklet server start
After a successful migration, your Blocklet Server instance will be running on the new database backend. You can manage your server as usual with commands like start and status.