Used to check for browser translation.
用于检测浏览器翻译。
ブラウザの翻訳を検出する
Command Reference

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

--dialect <dialect>

Required. Specifies the target database dialect. Supported values: postgres, sqlite.

Prerequisites#

Before running the migration, ensure the following conditions are met:

  1. Initialize Database: The Blocklet Server must have been started at least once to ensure the initial database and blocklet metadata exist.
  2. Stop Server: The server should be stopped before initiating the migration to prevent data corruption.
  3. Configure Target DB: If migrating to PostgreSQL, the ABT_NODE_POSTGRES_URL environment 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.

"Target DB (Postgres)""Source DB (SQLite)""Migration Script""Blocklet CLI""User""Target DB (Postgres)""Source DB (SQLite)""Migration Script""Blocklet CLI""User"Uses ABT_NODE_POSTGRES_URL to connectblocklet server migration --dialect postgresStart migration processValidate "postgres" dialectFetch list of all installed blockletsReturn blocklet dataRun schema migrations for each blockletConfirm successful migrationReport "Migration completed"blocklet server startBlocklet Server now connects to Postgres

Example: Migrating to PostgreSQL#

Here is a step-by-step guide to migrate your Blocklet Server instance from the default SQLite to PostgreSQL.

  1. Stop the Server
    If your Blocklet Server is running, stop it first.blocklet server stop

  2. Configure PostgreSQL Connection
    Set the ABT_NODE_POSTGRES_URL environment 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"

  3. Run the Migration
    Execute the migration command, specifying postgres as the target dialect.blocklet server migration --dialect postgres

    You 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

  4. 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.