Upgrading
This page is for the operator who moves a running Adiutor to a new release. It covers what to do beforehand, the upgrade on each kind of host, where the release notes are, how to go back, and the backups that make going back possible.
Every release follows the same order: get the new code, bring the database up to what it expects, and only then serve traffic with it.
Before you upgrade
Section titled “Before you upgrade”- Read the release notes (below) for the releases between yours and the new one. A release that needs more than the usual steps says so there.
- Back up the database and the attached files, together (see Backups). Migrations only go forward, so the backup is how you go back.
- Choose a quiet moment. The site is briefly unavailable while it restarts.
Upgrade
Section titled “Upgrade”-
Change the tag of the image in your
compose.yamlto the new version. Both theappand thejobsservice use the image, so change both lines. The image isbastolen/adiutor, tagged with the release:image: bastolen/adiutor:0.5.0 -
Pull the new image:
Terminal window docker compose pull -
Migrate the database with a one-off container, before anything serves the new version:
Terminal window docker compose run --rm app pnpm db:migrate -
Start the new version. Compose replaces the
appandjobscontainers:Terminal window docker compose up -d
The image never migrates the database by itself, so step 3 is yours every release. If you run the image with docker run instead, do the same with the new tag: pull it, run pnpm db:migrate in a one-off container, then start the new container. See Docker.
From the app’s folder, with the settings the server uses in .env. As on A plain Node.js server, the steps that change the code run as root (for example after sudo -i, with umask 022), and the migration as the app’s user. The app and its jobs stop while you build: a build starts from a fresh .next, and root never builds on top of the one the app’s user owns.
-
Stop the app and its jobs, a run under way included (the systemd units from A plain Node.js server). With cron instead of the timer, comment out its line in
crontab -u adiutor -eand stop only the app:Terminal window systemctl stop adiutor adiutor-jobs.timer adiutor-jobs.service -
Fetch the new release and check out its tag:
Terminal window git fetch --tagsgit checkout v0.5.0 -
Install the pnpm version the release names. It takes a moment when you have that version already, and keeps the app’s user from downloading one of its own:
Terminal window -
Install the dependencies, with the development ones (the build and the commands need them).
HUSKY=0skips installing Git hooks, which a server doesn’t need:Terminal window HUSKY=0 pnpm install --frozen-lockfile -
Build from a fresh
.next, then give the app its one folder back:Terminal window rm -rf .nextpnpm buildrm -rf .next/cache/turbopackchown -R adiutor:adiutor .next -
Migrate the database, as the app’s user:
Terminal window sudo -u adiutor -H env NODE_ENV=production pnpm db:migrate -
Start the app and its jobs again. With cron, start only
adiutorand put the cron line back:Terminal window systemctl start adiutor adiutor-jobs.timer
The example names this guide’s release: use the tag of the release you move to. The app is down from step 1 to step 7, so choose a quiet moment.
Production follows the production branch, which you move to the new release’s tag. Each build migrates the database first, through the environment’s unpooled connection, and when the migration fails the build fails and the previous deployment stays live. Following releases has the steps.
Why this order
Section titled “Why this order”Migrations bring the database to what the new code expects. The new build must therefore never serve traffic on the old schema, which is why you migrate before the restart. Migrate again with every release, even one that looks small.
Release notes
Section titled “Release notes”Every release has notes in two places:
- The changelog in the repository, written for each release by Release Please from the changes in it.
- The release’s page on GitHub, where a release that needs more from you than the usual steps says so.
Rolling back
Section titled “Rolling back”Migrations only go forward: there are no migrations that undo a change. Going back to an older version therefore means restoring the backup you took before upgrading, database and files together, and then starting the older version. Anything saved after the backup is lost, so decide quickly and tell people.
With the Compose file, stop the app and the jobs, give the database back its state from the dump, put the older tag back in compose.yaml and start again:
docker compose stop app jobsdocker compose exec -T db dropdb -U adiutor adiutordocker compose exec -T db createdb -U adiutor adiutordocker compose exec -T db pg_restore -U adiutor -d adiutor < adiutor.dumpdocker compose up -dRestore the files from the same moment before the last step.
On Vercel, rolling back to an earlier deployment doesn’t undo a migration either: the database keeps the newer schema. See Rolling back.
Backups
Section titled “Backups”Back up two things, at the same time, and keep them together:
-
The database. With
pg_dump, for example from the Compose database service:Terminal window docker compose exec -T db pg_dump -U adiutor -Fc adiutor > adiutor.dumpThe
-Tmatters: without it, Compose gives the command a terminal, which can damage the dump on its way to the file.With a hosted database, use its own backups, and take one before each upgrade.
-
The attached files, wherever they’re kept: the folder, the bucket or the SFTP folder. A file is found through its row in the database, so a database and its files only make sense as a pair. See Backups and moving storage.
Restore both together: the database from the dump, and the files from the same moment. Test a restore somewhere else before you need it.
Example
Section titled “Example”Adiutor at https://adiutor.dev runs from /srv/adiutor on a plain server. On a Sunday evening, the operator reads the changelog for the new release, takes a pg_dump and a copy of the files folder, checks out the new tag, installs, builds, migrates and restarts the service. They then open the site, sign in as Alex Admin and check that Logs › Jobs shows a recent tick.
Good to know
Section titled “Good to know”- When you skip releases, read the notes of every release in between.
- The Compose
jobsservice and the cron that runspnpm jobs:runmust run the same version as the app, so upgrade them with it. - A pinned tag (
0.5.0) keeps a restart from changing the version by accident. Don’t uselatest.
Related
Section titled “Related”Adiutor's code is released under the MIT License. The Adiutor name and logo aren’t covered by it; see the notice.
Set in Inter and JetBrains Mono, under the SIL Open Font License (Inter, JetBrains Mono).