Skip to content

Migrate SQLite / MySQL to PostgreSQL ​

Since v2.6.0, Next Terminal no longer supports SQLite or MySQL. Migrate these legacy databases to PostgreSQL before upgrading the application. See issue #538 for the announcement and manual examples.

Existing PostgreSQL deployments do not need this migration. For a PostgreSQL major-version change, see PostgreSQL 16 to 18.

Prepare ​

  1. Record the application version, image tags, deployment directory, and database connection settings.
  2. Back up configuration, Compose files, the database, and the entire data directory, including recordings, mounted-drive files, and certificates. Copy SQLite only after stopping writers; create a restorable MySQL backup. Store backups outside the deployment directory.
  3. Schedule downtime and stop Next Terminal and other source-database writers. Keep the source MySQL server available for migration.
  4. Prepare Python 3, Docker, sufficient disk space, and a separate empty PostgreSQL target database. Verify connectivity to both databases.

Run the official migration script ​

Download in the existing deployment directory, inspect the script, then run it:

shell
curl -fsSL https://raw.githubusercontent.com/next-terminal/next-terminal/master/scripts/migrate.py -o migrate.py
python3 migrate.py

Select SQLite or MySQL and provide source and target details. The script can create PostgreSQL, import with pgloader, and optionally update configuration, keeping .bak copies. These copies contain configuration only, not a database backup.

For MySQL on a private Docker network, select its actual network. A container's localhost refers to itself. Script options may change upstream; follow the downloaded version. If import fails, investigate before importing again into a partially populated database.

Check configuration ​

Verify the Database block points to the target (replace placeholders):

yaml
Database:
  Enabled: true
  Type: postgres
  Postgres:
    Hostname: postgresql
    Port: 5432
    Username: YOUR_PG_USER
    Password: YOUR_PG_PASSWORD
    Database: YOUR_PG_DATABASE
  ShowSql: false

For remote databases requiring TLS, replace the Postgres block with a URL:

yaml
Database:
  Enabled: true
  Type: postgres
  URL: "host=YOUR_PG_HOST user=YOUR_PG_USER password=YOUR_PG_PASSWORD dbname=YOUR_PG_DATABASE port=5432 sslmode=require TimeZone=Asia/Shanghai"

Review Compose services, networking, persistent paths, and application dependencies. Remove obsolete MySQL service references while retaining backups. Match PostgreSQL server and application client major versions as described in Installation.

Missing data after MySQL import ​

pgloader may place tables in a schema named after the source database while the application uses public. Before starting the application, inspect the target:

sql
SELECT table_schema, count(*) AS table_count
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'
  AND table_schema NOT IN ('pg_catalog', 'information_schema')
GROUP BY table_schema;

If needed, have a database administrator move objects to public, or rename the imported schema only after confirming public does not exist and there are no conflicts. Do not blindly drop public.

Verify and recover ​

Compare key table row counts, then upgrade and start the application using Installation. Check logs, sign in with an existing account, verify users, assets, credentials, policies, and settings, and test connections and recording playback before reopening access.

For rollback, stop the new application, restore the previous image, configuration, and matching source database backup, then start the old deployment. New writes do not automatically transfer back to the old database. Never run both deployments as writers.