An upgrade replaces the image and restarts the processes. In the default single-host Compose setup migrations run automatically as each process starts, so there is no separate schema step, which makes the backup step the one you must not skip. The production Compose file and the Kubernetes manifests work differently: they run migrations once, as a separate step, before anything starts (see below).

Before you start

Check the schema. migrate status reports the applied version and exits non-zero if a previous migration stopped part-way, which is the one state you must not deploy on top of:
See migrate status. Back up PostgreSQL. It holds every scan, finding, triage decision, accepted risk, policy verdict and schedule in the deployment, and a migration applied to it is applied for real.
Every migration has a down, so the schema is reversible in principle. But a down returns the schema, not the data a column drop took with it. The backup is what makes a rollback recover the second thing as well as the first. You do not need to back up Redis or the scanner cache: Discarding scanner_cache costs one slow scan while roughly 50 MB is re-fetched. That is a reasonable thing to do deliberately if you suspect a corrupt cache; it is not something to do routinely, because a worker that starts with a cold cache also starts with no vulnerability database, and the first scan pays for both.

The upgrade

Each process applies pending migrations before it serves anything. The runner takes a PostgreSQL advisory lock around the whole run, so several instances restarting at once serialise rather than racing, and a schema that is already current is a no-op. If a migration fails, the process exits with running migrations: … and does not serve traffic. That is the intended behaviour: a binary that finds a schema it does not understand should refuse to start rather than produce confusing runtime errors later.

Production: migrations are a separate step

infra/docker/docker-compose.prod.yml and the Kubernetes base set RUN_MIGRATIONS_ON_START=false, because there the API and worker connect as restricted login roles that cannot change the schema. A one-shot migrate up runs as the schema owner first (MIGRATION_DATABASE_URL), and the API and worker start only after it succeeds; each then checks that the schema is the one it was built for and refuses to start if not. infra/scripts/deploy.sh runs that sequence with a backup in front of it. See migrate.

Order of restart

Restart workers before or after the API: either is safe, and neither needs coordination.
  • A worker killed mid-scan has its lease expire, and the reaper returns the scan to queued. An abrupt stop costs one lease interval, not one lost scan.
  • A worker that shuts down on a signal leaves the interrupted run claimed and lets its lease expire, so the reaper returns it to queued intact, the same treatment a killed worker gets. It is deliberately not recorded as a failure: doing so would spend one of the scan’s attempts on work that was never actually tried, and three rolling restarts hitting the same scan would exhaust its retry budget and fail it permanently.
  • An API restart loses nothing: the scan row is committed before the response is returned, and the dispatcher republishes anything whose wakeup was lost.
  • On SIGTERM the API stops accepting connections and waits at most 20 seconds for open ones (a slow download, an idle keep-alive client), then closes its database pools and exits. Give it a stop grace period longer than that: the production Compose file sets 30 seconds on api, and the Kubernetes default is 30. Before 2026-10-13 the wait had no limit, so a single keep-alive client held the process until the orchestrator killed it.
If you run a single-process deployment (SCAN_WORKER_ENABLED=true on the API), the same applies: the restart is just one process instead of two.

What downtime costs a schedule

Nothing is silently lost, and nothing is replayed thirty times. If TRUSTIVAN is down for thirty days, thirty daily occurrences come due at once. The policy is run once, realign, count the rest:
  • One scan runs, not thirty. Thirty identical scans of one image would cost thirty times the registry bandwidth and tell you nothing the last one alone would not.
  • next_run_at advances in whole intervals from the planned time, so the original phase is preserved. A schedule that ran at 02:00 keeps running at 02:00 rather than drifting to whenever the system came back.
  • The skipped occurrences accumulate on the schedule as missed_runs and are shown in the dashboard, because a gap in coverage that nobody is told about is indistinguishable from continuous coverage.
Frequencies are hourly, daily or weekly, with one schedule per asset. There are no cron expressions, so there is no timezone or DST behaviour for an upgrade window to interact with: everything is stored as an absolute instant in UTC, which is precisely what “every 24 hours” needs so it does not become “every 23 or 25 hours” twice a year.

Verifying an upgrade

Then check three things beyond the probes:
  1. A scan completes. Submit one against a small public image and poll it to a terminal state.
  2. database_state on that scan is fresh. If the scanner cache was discarded or egress is blocked, this is where it shows.
  3. trustowl_scheduler_lag_seconds is falling back toward normal. A dead scheduler produces no work, so every other figure looks healthy. See Health and metrics.

Rolling back

Roll back the code, not the schema: put the previous images back and leave the database where the newer version left it. The application accepts a schema ahead of its own migrations, which is what makes that work whenever the migration was additive, and additive is the default for that reason. When it does not work, the migration was not backward-compatible, and the recovery is restoring the backup, not rolling the schema back: migrate down N reverses the last N migrations and the data in whatever they drop, so it is a development tool rather than an upgrade rollback tool. It refuses to drop the audit trail without --force-drop-audit. This is the practical reason the backup is not optional. Between a schema down that drops a column and a pg_dump taken twenty minutes earlier, only one of them returns the triage decisions that were in that column.

Deploy and roll back with the scripts

On a single Compose host, infra/scripts/deploy.sh runs the upgrade as gated steps, and each one either succeeds or stops the deploy:
  1. Preflight: changes nothing, and refuses anything that would fail later.
  2. Backup: before the migration, because that is the state to return to. It refuses to run without BACKUP_PUBLIC_KEY unless the environment file says BACKUP_ALLOW_UNENCRYPTED=true; see Backup and recovery. --skip-backup skips it when you have just taken one.
  3. Migrate: the one-shot job, as the schema owner.
  4. Start: the API, the worker and the frontends.
  5. Health: /ready from inside the container, so it tests the application and not the proxy.
  6. Smoke: the deployed system end to end. --no-smoke stops at health, for a stack with no public URL yet.
Choose the stack with ENV_FILE and COMPOSE_PROJECT_NAME in the shell. Two more settings, read from the shell first and then from the environment file, fit the scripts to a host that does not run every service: A successful deploy ends by printing the exact rollback.sh command for the images it replaced. The running image is given its own rollback-<timestamp> tag first, because a rebuild on the host moves the ordinary tag to the new build. If that image is already gone from the local store, the script says there is nothing to roll back to rather than print a target that is not one.
rollback.sh recreates only the services whose image changes (api and worker for the backend), with --no-deps, so migrate, db-roles, Postgres and Redis are not touched and the previous image’s migrations never run against the newer schema. It respects DEPLOY_SERVICES and runs the post-up hook.
Changed on 2026-10-13. Earlier versions of both scripts ran a bare docker compose up -d. In a rollback that started the previous image’s migrate against the newer schema, which exits with “no migration found for version N”, and Compose then left api and worker in Created: rolling back a deploy that carried a migration took the product down. The earlier backup step also wrote a plaintext dump when BACKUP_PUBLIC_KEY was unset. See the upgrade notes.

Configuration changes during an upgrade

Two settings are worth re-checking whenever you change versions, because both fail closed and both fail at startup rather than at use:
  • ENV must remain something other than development in a deployment. If a deploy accidentally sets it to development, secrets are regenerated per process instead of being required, and every session is invalidated on each restart.
  • VULN_DB_PROVIDER=mirror requires VULN_DB_REPOSITORIES. Startup fails if it is empty rather than silently reaching for the public internet, which either fails confusingly or, worse, succeeds and defeats the isolation you configured.
See Configuration overview.

What deployment tooling exists

Worth restating here, because an upgrade is when people go looking for it. Compose on a single host is the recommended path, and the gated sequence is infra/scripts/deploy.sh (preflight, backup, migrate, start, health, smoke) with infra/scripts/rollback.sh beside it; see above. Kubernetes manifests exist as a Kustomize base and its overlays, driven by make deploy-demo, make deploy-prod and scripts/deploy-k8s.sh hetzner; there is no Helm chart for the product. Terraform provisions a Hetzner cluster optionally and never deploys the application. There is no make deploy-staging and no make deploy-production: those names do not exist. See Topology for the full account of what is and is not included.