Upgrading and rolling back
How to move a running install to a new image: back up, migrate once, roll the api and worker, and roll back or stop sending safely if something breaks.
An upgrade is a new image plus the migrations it carries. This page gives the order that keeps sends flowing, how to roll back, and how to go live the first time.
# 1. Back up the database (keep SEQ_ENCRYPTION_KEYS with it)
pg_dump --format=custom --schema=seq --schema=auth "$SEQ_DB_DSN" > before-upgrade.dump
# 2. Apply the new image's migrations, once
docker run --rm -e SEQ_DB_DSN -e SEQ_ENCRYPTION_KEYS \
ghcr.io/lguerberg/open-sequence:NEW node dist/cli.js migrate
# applied 1 migration(s) or already up to date
# 3. Roll the api, then the worker, to the new imageHow migrations run
Every image ships the SQL migrations for the seq and seq_auth schemas. There are two ways to apply them, and both are safe to repeat:
| Way | When to use it |
|---|---|
node dist/cli.js migrate (oseq migrate) as its own step | production with several replicas: a pipeline step, a Fly release_command, a Kubernetes Job. A failed migration stops the release before any replica changes |
SEQ_RUN_MIGRATIONS=1 on the processes | a single container, or when you have no release step. Every process applies the migrations before it opens its port; replicas starting together wait on a row lock |
Each migration runs in one transaction and is recorded by tag and hash. A failed one rolls back and leaves the database as it was. There are no down migrations: going back means restoring the backup.
Rolling the roles
Old and new replicas run side by side during a rolling deploy. That is safe because the database arbitrates: runs are owned, claims use SKIP LOCKED, and every write re-checks state under a row lock.
- Migrate (step 2 above).
- Roll the
api. Its readiness probe (/readyz) holds traffic until the new replica reaches the database. - Roll the
worker. Each old worker finishes its in-flight messages for up to 30 seconds onSIGTERM; whatever it leaves reappears for the new workers when its visibility timeout ends.
The design rule is expand then contract: a migration adds columns and tables first, and a later release removes what is no longer used, so the old code keeps working against the new schema. When one release adds a capability that both roles share, deploy the role that adds it first.
0002 dropped tables, a column and an enum value in the same release that stopped using them, so older replicas fail against it. For a release whose notes say it removes something, scale the worker to zero, migrate, then start the new image for both roles.The public API only grows: new fields and endpoints are added, and nothing is removed or repurposed without a new version path. Every sequence definition so far is schema_version: 1.
Rolling back
Redeploy the previous image of the role at fault. The older image ignores migrations it does not know, so it boots against the newer schema, and an additive migration leaves it working.
If a migration damaged data, restore the backup into a new database and point both roles at it:
createdb -h db.internal opensequence_restore
pg_restore --dbname=postgres://oseq:…@db.internal:5432/opensequence_restore before-upgrade.dumpStopping sends in an emergency
| Lever | Speed | Effect |
|---|---|---|
project flag global off | immediate, no deploy | PUT /v1/engine/flags/global with { "value": false }: that project's sends are deferred |
SEQ_PAUSED=1 on the workers | one restart | the planner stops and every send is deferred, for all projects |
| scale the worker to zero | one deploy | hard stop; nothing is lost, everything resumes when a worker returns |
See Scaling for what each one leaves running.
The first go-live
- Provision Postgres and run
migrate. - Deploy the
api. Create the project and its key, register the provider credentials and your webhook endpoint. - Turn the project's
globalflag off, then deploy theworker. - Point your application at the service, behind your own feature flag.
- Enroll one contact with
"mode": "dry_run"and check the journey. Then turnglobalon and enroll a small batch.
A dry run is an enrollment with mode: "dry_run": it runs every wait and condition and sends nothing.