Skip to content

Upgrades and migrations

An upgrade replaces the coordinator binary or image and applies any new database migrations. Migrations only go forward, so the backup you take before an upgrade is your only way back.

No release has been published and the repository has no version tags yet. Until the first release, you upgrade by building a newer commit of main.

  1. Read the changelog. CHANGELOG.md follows Keep a Changelog. Every change a user can see is listed under Unreleased. Look for lines under Changed that ask you to do something, such as setting a new variable.

  2. Take a backup. See Backups.

  3. Record the audit chain head. Run audit verify and keep the last hash somewhere other than the database:

    Terminal window
    docker compose -f deploy/docker-compose.yml \
    run --rm --no-deps -T server audit verify
    audit chain ok: 1234 rows, head <hash>

    After the upgrade, run it again. The chain must still verify, and the row count must not be lower. See Security hardening.

  4. Upgrade zt too. Build zt from the same commit as the coordinator. No compatibility table between zt and coordinator versions exists yet.

The coordinator uses goose v3. The SQL files in server/migrations are compiled into the binary, so a binary always carries the migrations it needs. goose records the applied versions in its own table, goose_db_version.

There are two ways to apply them:

Command When it migrates
zentri-server migrate up Applies every pending migration, then exits.
zentri-server serve Applies every pending migration before it starts serving. --no-migrate skips this.

Both connect with ZENTRI_MIGRATE_DATABASE_URL, or with ZENTRI_DATABASE_URL when that is unset. Point ZENTRI_MIGRATE_DATABASE_URL at the role that owns the tables. ZENTRI_DATABASE_URL must be set even for migrate up, because the command checks it first.

A Postgres session lock keeps two processes from migrating at once.

Each applied file logs one line, and migrate up ends with a summary:

{"time":"...","level":"INFO","msg":"applied migration","version":10,"file":"00010_slack.sql","duration":12345678}
{"time":"...","level":"INFO","msg":"migrations up to date"}

The migration numbers have a gap: there is no 00007. 00010_slack.sql was numbered 7 until the model router and skill level migrations took 8 and 9.

  • They are forward-only in production. Each file has a Down section for development only. The server has no migrate down command.
  • A shipped migration is never edited. A fix is a new migration.
  • Each migration grants the coordinator role only what it needs. See Requirements and sizing.
  1. Get the new code:

    Terminal window
    git pull
  2. Rebuild and restart:

    Terminal window
    docker compose -f deploy/docker-compose.yml up --build -d

    Compose rebuilds the image, runs migrate as the owner, and recreates server when migrate exits with 0. If you use a second Compose file, name it too.

  3. Check the result:

    Terminal window
    docker compose -f deploy/docker-compose.yml logs migrate
    curl -fsS http://127.0.0.1:8080/readyz
    zt doctor

    The migrate log ends with migrations up to date. zt doctor prints the coordinator version on its token line.

The coordinator stops taking new connections on SIGTERM and gives requests in flight up to 10 seconds to finish. Compose runs one server, so expect a short outage while it is replaced.

  1. Back up the database. See Backups.

  2. Upgrade the release to the new image:

    Terminal window
    helm upgrade zentri deploy/helm/zentri --namespace zentri --reuse-values \
    --set image.tag=<new version> --wait

    The chart replaces the one coordinator pod with the Recreate strategy. The new pod’s migrate init container applies the new migrations as the owner, then the coordinator starts with --no-migrate. Expect a short outage.

  3. Check the result:

    Terminal window
    kubectl -n zentri logs deploy/zentri -c migrate
    zt doctor

    The migrate log ends with migrations up to date.

If a migration fails, the init container fails and the old pod is already gone. Read the migrate log, fix the cause, and the pod retries on its own. See Kubernetes.

Apply the migrations as the owner, then start the new binary with --no-migrate. In production, keep the URLs in an environment file or your service manager, not in your shell history.

Terminal window
ZENTRI_DATABASE_URL='postgres://zentri_coordinator:<password>@db.internal:5432/zentri' \
ZENTRI_MIGRATE_DATABASE_URL='postgres://zentri:<owner password>@db.internal:5432/zentri' \
zentri-server migrate up
Terminal window
zentri-server serve --no-migrate

zentri-server version prints the version, the commit and the build date of a binary.

Matching compares vectors of one model only. When you change ZENTRI_EMBEDDER or ZENTRI_EMBED_MODEL, embed the stored intents again once:

Terminal window
zentri-server intents reembed --all

Without --all, the command embeds only intents that have no vector yet. The coordinator also does that on its own every --reembed-interval (1 minute by default).

You cannot undo a migration with Zentri’s tools. To go back:

  1. Stop the coordinator.
  2. Restore the backup you took before the upgrade.
  3. Start the build you ran before.

Everything written after the backup is lost.

  • No published releases, images or version tags exist yet.
  • There is no migrate down and no migrate status command.
  • No compatibility rules between zt and coordinator versions are written down yet.
  • Compose runs one server, so an upgrade has a short outage.