Post

Immich backup schema validation added to CI pipeline

Immich backup schema validation added to CI pipeline

This push adds a schema check to the Immich backup CronJob so every published dump must contain the required application tables (user, asset, album, kysely_migrations) before it is published to QNAP, preventing incomplete archives from being promoted.

Implementation: backup.yaml now validates table definitions and data entries

The backup.yaml manifest was updated to pipe the output of pg_restore --list through an awk script that counts rows for each of the expected tables. If any table is missing or has zero data entries the job exits with a clear error message. The same logic is exercised by the new test suite in scripts/ci/immich-backup-test.py, which builds synthetic PostgreSQL listings and asserts that a valid set of tables passes while a deficient set fails.

Verification: test coverage confirms correct and incorrect dumps are rejected

The added immich-backup-test.py file defines a unit test that materialises a temporary directory, writes an expired dump and a fresh dump, then runs the backup command and checks the exit code. The test asserts that a dump containing all four tables (user, asset, album, kysely_migrations) succeeds, while a dump missing any of those tables exits non‑zero, matching the validation added to the production manifest.

Documentation: nightly job now checks each dump for required schema

The wiki page openwiki/architecture/storage-and-state.md was updated to describe that the nightly job now validates each dump for definitions and data entries for the Immich user, asset, album and migration tables before publishing to QNAP. An empty initialized library can pass, but a failed archive check preserves earlier backups, and recovery from database node loss now requires a verified restore that includes the schema.

Platform engineering: reusable pattern for backup‑schema gating

The approach of running a pg_restore --list query against a known table list and failing the job when expected objects are absent can be adopted for other PostgreSQL‑backed services in the homelab. By codifying the required schema in the CI pipeline, future upgrades or migrations can be validated before any artifact is promoted to the GitOps pipeline.

This post is licensed under CC BY 4.0 by the author.