Skip to content

Restore test: compare with the database as it was during the dump - #100

Merged
Delmar-Ramcic merged 1 commit into
mainfrom
fix/restore-test-race
Oct 22, 2026
Merged

Delmar-Ramcic merged 1 commit into
mainfrom
fix/restore-test-race

Conversation

@Oceandek

Copy link
Copy Markdown
Collaborator

Problem

The Deploy of #99 (chat basics) went live (migrations, services and health check all green), but its last step, Backup and restore test, failed: restore test FAILED: … differs from the live database.

Cause

backup.sh restore-test made the dump, restored it (~12 s), and only then counted the rows of the live database. Anything written in between makes the counts differ, even though the dump is fine. Right after the chat went live, people used it (messages, read marks), so the live database had changed.

Fix

  • The live row counts are taken just before and just after pg_dump. When they're equal, nothing changed during the dump, and the restored database must hold exactly those counts.
  • When they differ, the backup is made again after 5 s, at most 3 times; then the test fails with "the database kept changing during 3 backups".
  • On a failure, the live counts are printed next to the restored ones, so the log shows which table differs.
  • docs/backups.md and the changelog explain this.

Tested locally

In the test database container (postgres:16):

  • quiet database: restore test passed;
  • rows inserted every 0.1 s during the run: the first attempt says "the database changed during the backup; backing up again", the second passes.

Merging this runs the Deploy (and the restore test) again.

🤖 Generated with Claude Code

After #99 the Deploy's restore test failed: it counted the live rows after
restoring, and the site (now with the chat in use) had written meanwhile.
The live counts are now taken just before and just after the dump; when they
differ the backup is made again, at most 3 times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Delmar-Ramcic
Delmar-Ramcic merged commit 09f67c4 into main Oct 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants