Upgrade
Upgrade AI Gateway to a newer version using install.sh upgrade, including database backup, rollback, and post-upgrade verification.
Upgrades are handled by the same installer script that performed the initial
installation. Each version gets its own directory; the upgrade downloads and
extracts the new package, copies secrets from the current .env, runs
migrations, and switches current to the new version directory when the service
reports healthy.
Prerequisites
Section titled “Prerequisites”- Run from
aig/current. The script rejects execution from any other version directory. - The installation must be running (the bundled PostgreSQL must accept connections) so the installer can take a database backup before switching.
- If you use an external PostgreSQL, back it up with your own tools first and
then pass
--no-backup(see External PostgreSQL). - Log in to
harbor.chequer.ioas the user that runs the installer (see Registry login). When the upgrade is done, log out as the same user withdocker logout harbor.chequer.io(sudo docker logout harbor.chequer.ioif you logged in withsudo).
Upgrade steps
Section titled “Upgrade steps”From aig/current, run:
cd aig/current./install.sh upgrade 2026.11.15The script performs these steps in order:
- Validate inputs. Confirms the target version sorts higher than the installed version and that the required tools are available.
- Extract the new package. Downloads
package.tar.gzfromhttps://dl.querypie.com/releases/ai-gateway/<version>/(or uses--package) intoaig/<version>/. If.envdoes not yet exist in that directory, copies the current.envinto it, updatesVERSION, and appends any keys that the newenv.templateadds. - Verify datastores. Checks that
COMPOSE_PROFILESis consistent withDATABASE_URLandREDIS_URLin the new.env. - Pull images. Pulls the images for the new version from
harbor.chequer.io. A pull failure aborts before any running service changes (see Image pull failure). - Back up the database. Dumps the bundled PostgreSQL to
aig/<current_version>/backups/aig-<current_version>-<timestamp>.dumpusingpg_dump -Fc. Skipped when--no-backupis passed. Rejected with an error whenDATABASE_URLis set without--no-backup. - Start the new version. Runs
docker compose up -d --remove-orphansfrom the new version directory, somigrateruns against the new schema first. Waits for/readyzto respond (up to 300 seconds). - Switch
current. Pointsaig/currentat the new version directory. - Print next steps. Logs the base URL and bootstrap token location.
Offline upgrade
Section titled “Offline upgrade”If the host cannot reach dl.querypie.com, download the package on another
machine and copy it to the host, then pass --package:
./install.sh upgrade 2026.11.15 --package /tmp/package-2026.11.15.tar.gzThe path may be absolute or relative to the directory from which you invoke the
script (not aig/current).
External PostgreSQL
Section titled “External PostgreSQL”When DATABASE_URL is set in .env, the installer cannot reach the external
database to take a dump. Back up the external database with your own tools, then
pass --no-backup:
./install.sh upgrade 2026.11.15 --no-backupRunning upgrade without --no-backup when DATABASE_URL is set is rejected:
[aig] ERROR: DATABASE_URL points to a PostgreSQL this script cannot back up; back it up with your own tools, then run './install.sh upgrade 2026.11.15 --no-backup'Failure behaviour
Section titled “Failure behaviour”If any step fails, the script exits immediately (the script runs with
set -euo pipefail). The previous version continues running because current
is not switched until after /readyz responds. The partially created
aig/<version>/ directory is left in place; running the same upgrade command
again reuses it and keeps the .env already copied into it.
If the database backup step fails (for example because PostgreSQL is not running or disk space is insufficient), the script aborts before touching the running service:
[aig] ERROR: database backup failed; start the installation first or pass --no-backupRollback
Section titled “Rollback”The previous version directory and its .env remain on disk after an upgrade.
To roll back, run every command from the previous version directory. That
directory holds both the Compose file to start and the backups/ dump the
upgrade created.
cd aig/2026.11.01docker compose stop server webdocker compose exec -T postgres dropdb -U ai_gateway ai_gatewaydocker compose exec -T postgres createdb -U ai_gateway ai_gatewaydocker compose exec -T postgres pg_restore -U ai_gateway -d ai_gateway \ < backups/aig-2026.11.01-<timestamp>.dumpdocker compose up -d --remove-orphansln -sfn 2026.11.01 ../currentThe dropdb/createdb pair matters: a failed upgrade may have left partial
schema changes in the shared aig_pgdata volume, and restoring into a
non-empty database fails. If you use an external PostgreSQL, skip those three
database commands and instead restore the backup you took before the upgrade
using your own tools.
Note: encrypted values in the database (IdP client secrets, provider API keys)
are readable only with the DB_FIELD_ENCRYPTION_KEY from the .env that was
in use when they were written. If you rolled forward and new encrypted values
were written with the new .env, rolling back to the previous .env makes
those new values unreadable. Roll back as soon as possible after detecting a
problem, before any new configuration is saved.
Post-upgrade verification
Section titled “Post-upgrade verification”After a successful upgrade, verify the new version is running:
cd aig
# Confirm current points to the new version directory.readlink current
cd current
# Confirm the service reports healthy. If you changed AIG_HTTP_PORT from its# default of 80, append it: http://127.0.0.1:8080/readyzcurl -sf http://127.0.0.1/readyz && echo "ok"
# Confirm the VERSION in .env matches the upgraded version.grep ^VERSION .envIn the browser, the last line of the Account menu at the top right shows the same version. Reload the page if it still shows the previous one.
The installer also prints the base URL; confirm the gateway is reachable through the load balancer:
curl -sI https://aig.example.com/api/auth/capabilitiesExpect HTTP/2 200 and the header X-Content-Type-Options: nosniff.