# Upgrade dropshelf

Source: https://dropshelf.ai/docs/self-host/operate/upgrade

Move a dropshelf instance to a newer release with Helm, one minor version at a time, and roll back if you need to.

This page is for operators who run dropshelf on Kubernetes with the Helm chart. An upgrade is a
rolling update with no downtime: old and new pods serve side by side until the rollout ends.

## What a release promises [#what-a-release-promises]

The server, the image, the Helm chart and the `dropshelf` CLI share one version, made by one git
tag. A release line is a major and minor version, such as `v1.4`, with all its patches. Each kind
of release promises the following:

| Release | Example | What it promises |
| --- | --- | --- |
| Patch | `v1.4.2` to `v1.4.3` | Fixes only. It adds no setting, metric or command, and carries a migration only for a security or data-loss fix. |
| Minor | `v1.4.2` to `v1.5.0` | Adds features, settings and metrics. Everything that worked keeps working, and its migrations are safe for the previous line's binary. |
| Major | `v1.x` to `v2.0.0` | Removes or changes something, and only what a minor release announced at least one line before. |
| Before 1.0 | `v0.4.x` to `v0.5.0` | A minor release may break as well as add. Its release notes list every break first, with what to do about it. |

Within a line, you can move between patches forwards or back at will, with no migration to plan.

## Upgrade one minor version at a time [#upgrade-one-minor-version-at-a-time]

Go from one line to the next and never skip a line, so `v0.4` goes to `v0.5` before `v0.6`. Each
migration is safe for the previous minor's binary only, and a rolling update runs that binary
against the new schema until the last old pod stops.

## Prerequisites [#prerequisites]

- `helm` and `kubectl` access to the `dropshelf` namespace.
- A backup of the database taken right before the upgrade, as in
  [Back up and restore](/docs/self-host/operate/backup). There are no down migrations.
- The release notes of the target release. A minor release lists new defaults, deprecations and
  migrations first.

## Upgrade with Helm [#upgrade-with-helm]

To upgrade the instance:

1. Check the release you run now.

   ```bash
   kubectl exec -n dropshelf deploy/dropshelf -- /dropshelf-server version
   ```

   The output is similar to:

   ```text
   dropshelf v0.4.2 (3f9c2e1a)
   ```

2. Back up the database, as in [Back up and restore](/docs/self-host/operate/backup).

3. Upgrade the release to the chart version of the next line. The chart version carries the
   image tag, so this one command moves both.

   ```bash
   helm upgrade dropshelf oci://ghcr.io/dropshelf/charts/dropshelf --version <version> -n dropshelf -f values.yaml
   ```

   `<version>` is the release without the `v`, such as `0.5.0`. If your values file sets
   `image.tag` or `image.digest`, change it to the same release, or remove it so the chart uses its
   own. The chart refuses `latest` and other moving tags.

4. Wait for the rollout to finish.

   ```bash
   kubectl -n dropshelf rollout status deployment/dropshelf
   ```

### How migrations run [#how-migrations-run]

The chart runs migrations in one of two ways, set by
[`migrations.mode`](/docs/reference/helm-values#migrations):

- **`startup`**, the default: every new pod migrates the database as it starts. Pods that start
  together take a lock in turn, and the second finds nothing to do.
- **`job`**: a pre-upgrade hook Job runs `dropshelf-server migrate` before any pod is replaced, and
  the servers never migrate. This keeps schema changes out of the serving path.

In `job` mode, Helm deletes the Job when it succeeds. If it fails, the upgrade stops before any pod
changes and the old release keeps serving. Read why with this command:

```bash
kubectl -n dropshelf logs job/dropshelf-migrate
```

## Confirm it worked [#confirm-it-worked]

1. Check that `kubectl -n dropshelf rollout status deployment/dropshelf` returned and every pod is
   ready.
2. Check the running release with `/dropshelf-server version`, as in the first step. The
   `dropshelf_build_info` metric carries the same `version` and `commit` labels.
3. Publish a small drop and open it. Readiness proves the database and the bucket answer, not that
   a publish goes through.

## Roll back [#roll-back]

The schema never rolls back, so what is safe depends on how far you go back:

- **To another patch of the same line:** always safe, with nothing to plan.
- **To the previous minor release:** safe, because its binary runs against the new schema. Run
  `helm rollback dropshelf -n dropshelf`, which returns to the previous Helm revision and its image.
- **More than one minor release back:** not supported. Restore the backup you took before the
  upgrade instead, together with the release that took it.

Published drops do not change in a rollback. Every version is immutable, so an older binary serves
the same files.

<Callout type="warn">
Restoring the database backup loses every change made after it was taken: new drops, versions,
comments, members and tokens.
</Callout>

## Members' CLIs [#members-clis]

Every answer from the instance names its release, so each member's CLI notices an upgrade on its
next command. When the CLI is a minor version or more behind, it prints one line after the command:

```text
This CLI is v0.4.2 and https://drop.example.com runs v0.5.0: run dropshelf upgrade to match it.
```

`dropshelf upgrade` installs the newest patch of the instance's line. Before 1.0, a member's CLI
belongs on the instance's minor line. A release whose API change would make an older CLI do harm
raises the oldest CLI the instance accepts and says so in its notes. The instance then refuses an
older CLI with status 426 and tells the member to run `dropshelf upgrade`.

## Next steps [#next-steps]

- [Back up and restore](/docs/self-host/operate/backup)
- [Monitor an instance](/docs/self-host/operate/monitor)
- [Troubleshoot an instance](/docs/self-host/operate/troubleshooting)
- [Helm chart values](/docs/reference/helm-values)
- [CLI commands](/docs/reference/cli)
