Run migrations and upgrade
SupaCloud uses sqlx numbered migrations in
server/migrations/. The server runs every pending migration automatically on
boot by default. With SUPACLOUD_SKIP_BOOT_MIGRATIONS=true, startup only verifies
that the required migrations are applied; run supacloud-server migrate as the
separate deploy step before starting that version. This guide covers the default
upgrade sequence: back up first, pull the new image, restart.
supacloud-server migrate applies pending migrations. The binary has no
migration planning or dry-run mode: --plan, --dry-run, unknown arguments and
conflicting process modes are refused before configuration or database access.
Starting the binary without arguments starts the Hub, including its configured
boot migration policy; it is not a read-only migration check.
Before you start
Section titled “Before you start”-
You need write access to the host running the Docker Compose stack.
-
Confirm the stack is healthy before upgrading:
Terminal window docker compose -f docker-compose.yml -f compose.standalone.yml psAll services should show
healthyorrunning. Do not upgrade a degraded stack.
1. Back up the database
Section titled “1. Back up the database”Take a logical database dump before pulling a new image. This covers one database, not cluster roles, tablespaces or artifact files/volumes. Preserve those through your reviewed backup procedure alongside the database.
-
Stop the server to hold its writes during the upgrade; leave Postgres running for the dump:
Terminal window docker compose -f docker-compose.yml -f compose.standalone.yml stop server -
Dump the database to a local file:
Terminal window backup_file="supacloud-backup-$(date +%Y%m%d-%H%M%S).sql"if docker compose -f docker-compose.yml -f compose.standalone.yml \exec -T postgres pg_dump -U supacloud supacloud > "$backup_file"; thenif [ ! -s "$backup_file" ]; thenprintf '%s\n' 'Dump is empty; stop the upgrade.' >&2exit 1fielsedump_status=$?printf 'Dump failed (exit %s); stop the upgrade.\n' "$dump_status" >&2exit "$dump_status"fiReplace
supacloudwith yourPOSTGRES_USER/POSTGRES_DBvalues from.envif you changed them from the defaults. -
Record the actual dump/Compose exit and inspect its diagnostics. A non-empty file alone is not a complete backup. Keep failed or partial output separate; do not use it for recovery. Before upgrading, qualify this backup through the isolated restore and readback procedure.
2. Pull the new image and restart
Section titled “2. Pull the new image and restart”-
Pull the new image:
Terminal window docker compose -f docker-compose.yml -f compose.standalone.yml pull server -
Start the stack:
Terminal window docker compose -f docker-compose.yml -f compose.standalone.yml up -dThe
serverservice waits for thepostgreshealth check, then runs all pending migrations before opening the HTTP port. Watch the log to confirm:Terminal window docker compose -f docker-compose.yml -f compose.standalone.yml logs -f serverYou should see a line similar to:
Database migrations complete -
Confirm the stack is healthy:
Terminal window docker compose -f docker-compose.yml -f compose.standalone.yml ps
Isolated restore and readback
Section titled “Isolated restore and readback”Use this procedure to qualify the backup before upgrading and to prepare recovery after a failed migration. Keep the original database, runtime and backing stores; do not feed a plain SQL dump into an existing or partially migrated database.
-
Under your reviewed recovery runbook, provision a separate isolated PostgreSQL instance and empty database created from
template0. Verify its instance, Compose project and database identity. It must have separate storage and no connection from live applications. Match the source PostgreSQL/tool versions, provision the required cluster roles and tablespaces, and make compatible extension packages available. A single-databasepg_dumpdoes not capture cluster roles or tablespaces. Do not drop or recreate the original database. -
Set
RESTORE_PROJECT,RESTORE_COMPOSE_FILE,RESTORE_DB,RESTORE_USERandBACKUP_FILEto the reviewed isolated target and the qualified dump. These variables must never identify the original stack. Import the plain SQL dump without a TTY or local psql startup settings, stopping on the first SQL error:Terminal window : "${RESTORE_PROJECT:?Set the isolated restore project}": "${RESTORE_COMPOSE_FILE:?Set the reviewed isolated Compose file}": "${RESTORE_DB:?Set the empty isolated database}": "${RESTORE_USER:?Set the reviewed restore role}": "${BACKUP_FILE:?Set the qualified dump path}"if docker compose -p "$RESTORE_PROJECT" -f "$RESTORE_COMPOSE_FILE" \exec -T postgres psql -X --set ON_ERROR_STOP=on \-U "$RESTORE_USER" -d "$RESTORE_DB" < "$BACKUP_FILE"; thenprintf '%s\n' 'Import exited successfully; restore validation is still required.'elserestore_status=$?printf 'Restore failed (exit %s); keep the target isolated.\n' "$restore_status" >&2exit "$restore_status"fiA failed import can leave a partial isolated database. Stop and retain the evidence; do not switch to it or rerun into it as a repair. This command does not promise a complete rollback or automatically clean a failed target.
-
Require a successful import exit and reviewed schema, ownership, migration ledger, data and application readback against the restored copy. Keep that validation environment isolated from live users and external integrations. Record the results and preserve the original database/stores. Only an approved recovery window may switch the application to the validated restored target.
See PostgreSQL’s SQL dump and restore guidance and psql error handling.
What to do if a migration fails
Section titled “What to do if a migration fails”If the server exits with Migration failed: in its log:
- Keep the server stopped and preserve the original database and stores. Do not force-restart in a loop: each attempt can repeat migration work.
- Investigate the failure and follow isolated restore and readback. A backup import into the original populated database is not a rollback.
- Record the migration filename and sanitized error diagnostics in an issue. Retry or switch databases only under the reviewed recovery plan; retain the original until the restored target and application readback are accepted.
Related
Section titled “Related”- Self-host with Docker Compose — initial setup
- Environment variables —
DATABASE_URLand other required variables - Secret provisioning — moving secrets out of
.env - Run as a least-privilege database role — separate the migration owner from the runtime role