Black Branch/Docs
All sections

Updates and the database

This page is for owners who want to know why updates are safe to let run. After reading it you can explain how the database gets its shape and keeps it through updates, what a release is, and how your server knows a release is genuine.

The steps an update takes, the commands and what rollback does are on Updates and rollback. Backups and restores are on Backups and restore.

Migrations

The platform's database changes shape over time: a new feature needs a new table or column. Each change is one numbered file, a migration, applied in number order. Each one makes its change and then records itself in a table called public.schema_migrations (its version number and a short note). That table is the record of what has been applied, so nothing is ever guessed.

The rules every migration follows:

Who runs them: the migrate job

Every time the install starts, before stream-api, stream-ingest or the website, a one-shot container called migrate runs and then exits. The other programs wait for it to succeed, so they never run against a database older than their code. It decides what to do from what it finds:

The database is It does
Empty (a new install) Builds it from the baseline, then applies every migration newer than the baseline
One it built before Applies only the migrations not yet recorded, or says it is up to date
Not empty, but with no schema_migrations table Refuses and stops. A database it did not make is not its to change

You can also run it by hand:

sudo blackbranch migrate

The fresh-install baseline

The full list of migrations is long, and much of it is history: tables made and later dropped, columns renamed, data moved. Replaying all of that on every new install would be slow and would carry every old mistake along. So a new install starts from a baseline instead:

Both are applied together in one transaction, then any newer migrations. The seed runs again, harmlessly, on every start, so a row that went missing for any reason comes back.

The project checks the baseline on every change: in a throwaway database it builds the database both ways (every migration from the start, and baseline plus seed plus newer migrations) and compares every table, column, index, constraint, function and seed row. Any difference fails the change. So a new install and a years-old install end up with the same database.

The pgvector add-on needs a database superuser to install it. The baseline is the only step that needs one: for that step alone the job raises the platform's own database user to superuser and lowers it again afterwards. Every table ends up owned by the platform's user, and nothing else runs with more rights than it needs.

Your .env has migrations too

The settings file .env can also need changes when a release renames, adds or retires one of its keys. Each release carries small numbered scripts for that, and BB_ENV_VERSION in .env records the last one applied. They never print a value. An update runs them on a copy of .env first, and stops before changing anything if the result would be missing a key the release needs.

Releases

A release is one version of everything on the server, pinned exactly:

How your server knows a release is genuine

The newest release on each channel (stable or beta; every release so far is a preview on beta) is announced in a signed feed, a small file the project publishes at blackbranch.app/releases. Your server checks the signature with the one public key it was installed with (BB_RELEASE_KEY in .env). The signature uses Ed25519 in a DSSE envelope: the announcement travels as exact bytes and the signature covers those bytes, so no two programs can disagree about what was signed. An update never changes the key.

Your server refuses:

Why an update backs up before it switches

Migrations only move forward: there is no "undo" file for each one. Going back to an older release therefore means going back to the database as it was before the new release's migrations ran. That is why every update stops the site, makes a backup, and only then switches to the new release. If the new release fails its health check, the server restores the databases from that backup instead of trying to reverse the changes. The whole sequence is on Updates and rollback.

Next: Docs home

← How it works