Upgrading

How the schema moves between releases, upgrading a single node and a cluster with a rolling upgrade, going back, and upgrading agents.

On this page

Status. Tested: the migration runner (advisory lock, one transaction per migration, compatibility refusals, unknown newer migrations) in the product's database tests. The mixed-versions drill exists but was not run for these docs. Not yet run: an upgrade between two published releases (0.1.0 is the first).

Releases follow semantic versioning: while the major version is 0, a minor release may change behaviour and a patch release only fixes. Read the release notes first, and back up the database before every upgrade (backup and restore).

How the schema moves

  • Migrations are embedded in the binary, forward-only, one transaction each, applied under an advisory lock, so two nodes migrating at once apply each migration once.
  • The database records schema_compat: the oldest Structam version that may run against it. Most migrations only add (tables, nullable columns, indexes) and leave it alone, so nodes of the previous release keep running during a rolling upgrade. A migration that breaks older binaries raises it.
  • A node older than schema_compat refuses to start, and a running one that finds it raised drains and exits with a message naming structam migrate.
  • A binary refuses to migrate a database whose schema is newer than it knows.

Check before you upgrade, with the new binary against the live database:

structam migrate -check      # exits 1 when migrations are pending or the schema needs a newer release; changes nothing

Single node

STRUCTAM_MIGRATE=auto (the default for single nodes) applies pending migrations at start. The migration step has no time limit: a long one (an index built on a large table) logs schema migrations are still running every minute. Do not restart or stop the node meanwhile: that rolls the running migration back, and the next start begins it again.

Docker Compose:

cd deploy/compose
docker compose exec -T db pg_dump -U structam -Fc structam > ~/structam-before-upgrade.dump
# set STRUCTAM_IMAGE in .env to the new image, then:
docker compose up -d             # the new app migrates and starts
docker compose exec app structam version

Server installer: re-run it with the new binary. It replaces the binary (keeping structam.previous), runs structam-migrate.service, restarts the service and waits until it is ready:

sudo deploy/install/install.sh --binary ./structam --public-url https://structam.example.com

Cluster (rolling)

Every node runs with STRUCTAM_MIGRATE=off. Migrate once with the new binary, then replace the nodes one at a time:

  1. Run structam migrate -check with the new binary. The release notes say when a release raises schema_compat; then the old nodes stop as soon as the migration commits, so plan a short outage or upgrade every node right away.
  2. Back up the database.
  3. Migrate once: on one host install the new binary and systemctl start structam-migrate (or install.sh --role serve --migrate); on Kubernetes delete the finished Job and apply the new image (upgrading on Kubernetes).
  4. Replace the nodes one at a time. Each drains on SIGTERM (stopping a node), so agents move to the other nodes and nothing is lost. Kubernetes Deployments roll with maxUnavailable: 0.
  5. Check System → Nodes: every node on the new version, no configuration-hash mismatch.

Nodes of the old and new version run side by side during step 4; System → Nodes flags the version skew until the last one is replaced.

Going back

Migrations are forward-only. To go back to the previous release, stop every node, restore the database backup taken before the upgrade, and start the previous binary. If no migration raised schema_compat, the previous binary also runs against the new schema (it logs the unknown migrations), and no restore is needed.

Agents

Agents are designed to update themselves from the server, one signed release at a time:

  1. A release image carries the agent release of its version, and every serve node stores it at start. Another release is imported with structam agent-release import DIR.
  2. structam agent-release publish -version X.Y.Z offers it to agents whose policy has auto_update (the default policy has it), at most STRUCTAM_AGENT_UPDATE_RATE (60) per minute across the cluster. structam agent-release pause -channel stable stops it. Update agent on an agent's page updates one agent by hand.
  3. Each agent verifies the manifest's signature with the release keys compiled into it, checks the binary's SHA-256 and size, swaps the binary (keeping the old one), and restarts. A build that fails to report three times in a row is rolled back and never offered to that agent again. A download or install that fails before the swap keeps the running version and is offered again after 24 hours.

Caution. The KazLabs release key has not been generated yet. Until its public half is compiled into the agents, release agents refuse every self-update, and hosts are upgraded with the install script: install.sh --upgrade (or install.ps1 -Upgrade), which waits until the new version is connected.

Questions the docs do not answer?

Ask the people who build Structam. Installation media and licences come from KazLabs.

Talk to us