Migrate Database
The blocklet server migrate
command facilitates the transition of your Blocklet Server's database from one system to another. This is particularly useful when scaling your setup from the default SQLite database to a more production-ready solution like PostgreSQL, which offers enhanced performance and scalability.
Usage#
The command requires you to specify the target database dialect.
blocklet server migrate --dialect <dialect>
Options#
Option | Description |
---|---|
| Specifies the target database system for the migration. Supported options: |
Example: Migrating from SQLite to PostgreSQL#
Follow these steps to migrate your existing Blocklet Server data to a PostgreSQL database.
Prerequisites#
- PostgreSQL Server: You must have a running PostgreSQL server that is accessible from the machine where you are running the command.
- Initialized Server: Your Blocklet Server must have been started at least once to initialize the source SQLite database. If not, the migration will fail with an error like
SQLITE_ERROR: no such table
. - Backup: It is highly recommended to back up your existing Blocklet Server data directory as a precaution before starting the migration process.
Step 1: Configure the PostgreSQL Connection#
The migration tool requires the connection string for your target PostgreSQL database. Provide this by setting the ABT_NODE_POSTGRES_URL
environment variable.
# Replace with your actual PostgreSQL connection string
export ABT_NODE_POSTGRES_URL="postgres://user:password@localhost:5432/abtnode_db"
Step 2: Run the Migration Command#
Execute the migrate command, specifying postgres
as the target dialect. The tool will connect to both the old SQLite database and the new PostgreSQL database to transfer the schema and data for the server core and all installed blocklets.
blocklet server migrate --dialect postgres
Step 3: Verify and Restart#
Upon successful completion, the CLI will display a confirmation message indicating that the migration is finished and instructing you on the next step.
Migration postgres completed
Please start server, will use Postgres database: blocklet server start
Your data has now been migrated. To begin using the new PostgreSQL database, restart the Blocklet Server as prompted:
blocklet server start
The server will now connect to and operate using the configured PostgreSQL database.