Upgrade the runtime
An upgrade has four stages: prepare, back up, migrate, and roll out. Migrations are forward-only, so the backup is the only way back to the previous version. The compatibility policy defines the supported upgrade path.
Prepare
Read the changelog entries for every version after your current version, up to the target version. Note breaking changes, deprecations, new configuration fields, and migration notes.
Validate your configuration with the target version:
enterprise-runtime check-config /path/to/config.yamlThe command checks the configuration shape and the compiled provider capabilities. It does not connect to the database or the identity provider.
Make sure the environment secrets for the target configuration exist, including the current and previous master keys.
Back up
Take a database backup and confirm that it completed. Confirm that the master keys from the configuration are in your secret store. See backup and restore.
Run migrations with the migration role
Production deployments use a separate database role for migrations. That role can change the schema. The runtime role gets only the access that the runtime needs. See security and deployment.
Run the migrations once, with the target version and the migration role's database URL:
DATABASE_URL="$MIGRATION_DATABASE_URL" enterprise-runtime migrate /path/to/config.yamlThe variable name must match storage.database_url_env in the configuration.
The command applies each pending migration in order.
Each migration runs in its own transaction.
If a migration fails, the database keeps the migrations that completed before it.
Turn off migrations at startup for the target version:
storage:
migrate_on_startup: falseThe replicas then use the runtime role and only check that no migration is pending.
A replica that finds pending migrations waits at the migrations startup step and does not become ready.
See run the runtime.
The v0.5.0 runtime has no separate migration command.
It applies pending migrations when serve or bootstrap starts.
To upgrade from v0.5.0, either let the first replica of the target version migrate at startup, or run migrate from the target version first.
Roll out the replicas
Replace the runtime replicas one at a time with the target version.
Wait until each new replica returns HTTP 200 from /readyz before you replace the next one.
/healthz reports only that the process serves HTTP.
During the rollout, replicas of the previous version keep running against the migrated schema. If the changelog says that the previous version cannot run against the new schema, stop all replicas before you run the migrations.
After the migrations, a replica of the previous version starts again only if migrate_on_startup is false in its configuration.
With migrations at startup, it finds migrations that it does not know and exits.
v0.5.0 always migrates at startup, so do not restart v0.5.0 replicas during the rollout.
Helm
The chart in deployments/helm/open-enterprise can run the migrations as a pre-install and pre-upgrade hook Job.
Set migration.enabled to true and give the Job the migration role's credentials through migration.secretEnv or migration.envFromSecrets.
The hook Job runs enterprise-runtime migrate with the chart's configuration.
The chart also sets storage.migrate_on_startup to false in the configuration it renders for the replicas.
The Deployment then rolls out with maxUnavailable: 0, and its readiness probe uses /readyz.
Upgrade without downtime
Replicas of the previous version can keep serving requests while migrate runs and while new replicas replace them.
Two rules make this work.
The previous version must run against the new schema. A release's migrations add tables, columns that are nullable or have a default, indexes and constraints. They don't remove or rename anything the previous release reads or writes; that waits for a later release. When a release can't follow this rule, its changelog migration notes tell you to stop every replica before you migrate.
The migrations must not stall requests.
migrate runs on its own database connection without the 10-second statement limit that requests have, so an index build on a large table can take as long as it needs.
It waits at most five seconds for each lock.
If running requests hold a lock longer, the migration gives up, waits a few seconds, and tries again, up to five times.
Each migration runs in one transaction, so a migration that gave up leaves nothing behind.
After the fifth attempt, migrate fails with a migration gave up waiting for a lock that requests hold.
Look for long transactions in pg_stat_activity, or run the upgrade when traffic is lower.
A migration that rewrites or indexes a table still blocks writes to that table while it runs. Requests that wait longer than their 10-second statement limit fail with HTTP 503, which the TypeScript SDK retries for requests that are safe to repeat. Check the changelog migration notes for large tables before you choose when to upgrade.
The full sequence is:
- Run
migratefrom the target version with the migration role, while the previous version serves traffic. - Roll out the target version one replica at a time, as described above, with
migrate_on_startup: false. - Verify the upgrade.
Verify
- Check that every replica runs the target version and is ready.
- Read a known organization and recent audit events through the API.
- Sign in through each identity provider connection that you use.
- Check that event consumers advance and that webhook deliveries succeed.
Recover from a failed upgrade
If a migration fails, stop and read the error. The failed migration leaves no changes, but the migrations before it stay applied. If at least one migration completed, a replica of the previous version that migrates at startup cannot restart.
To return to the previous version:
- Stop every runtime replica.
- Restore the backup from before the upgrade.
- Start the previous version.
Changes made after the backup are lost. Event consumers that received events after the backup point must reconcile. See backup and restore.