Skip to content

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.

  • 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 ps

    All services should show healthy or running. Do not upgrade a degraded stack.

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.

  1. 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
  2. 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"; then
    if [ ! -s "$backup_file" ]; then
    printf '%s\n' 'Dump is empty; stop the upgrade.' >&2
    exit 1
    fi
    else
    dump_status=$?
    printf 'Dump failed (exit %s); stop the upgrade.\n' "$dump_status" >&2
    exit "$dump_status"
    fi

    Replace supacloud with your POSTGRES_USER / POSTGRES_DB values from .env if you changed them from the defaults.

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

  1. Pull the new image:

    Terminal window
    docker compose -f docker-compose.yml -f compose.standalone.yml pull server
  2. Start the stack:

    Terminal window
    docker compose -f docker-compose.yml -f compose.standalone.yml up -d

    The server service waits for the postgres health 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 server

    You should see a line similar to:

    Database migrations complete
  3. Confirm the stack is healthy:

    Terminal window
    docker compose -f docker-compose.yml -f compose.standalone.yml ps

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.

  1. 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-database pg_dump does not capture cluster roles or tablespaces. Do not drop or recreate the original database.

  2. Set RESTORE_PROJECT, RESTORE_COMPOSE_FILE, RESTORE_DB, RESTORE_USER and BACKUP_FILE to 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"; then
    printf '%s\n' 'Import exited successfully; restore validation is still required.'
    else
    restore_status=$?
    printf 'Restore failed (exit %s); keep the target isolated.\n' "$restore_status" >&2
    exit "$restore_status"
    fi

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

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

If the server exits with Migration failed: in its log:

  1. Keep the server stopped and preserve the original database and stores. Do not force-restart in a loop: each attempt can repeat migration work.
  2. Investigate the failure and follow isolated restore and readback. A backup import into the original populated database is not a rollback.
  3. 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.