fix(demo): keep a demo baseline per engine and check it before every reset

The baseline was travel-baseline.db on both engines and went straight into
the swap, so a SQLite baseline left in the data directory made every hourly
reset of a Postgres demo fail inside pg_restore, and never got replaced. It
is now named after the engine's archive entry (travel-baseline.db on
SQLite, travel-baseline.pgdump on Postgres), and the backup port's new
checkCopy refuses one the engine cannot restore before the swap; the reset
then saves a fresh baseline and logs the reason instead of failing hourly.
This commit is contained in:
Maurice
2026-11-17 12:19:13 +01:00
parent 7a99190550
commit 99c3c670a5
11 changed files with 144 additions and 4 deletions
@@ -32,6 +32,11 @@ export async function checkPostgresDump(extractDir: string, binDir: string | und
? 'This backup holds a SQLite database, which cannot be restored into a Postgres database.'
: `Invalid backup: ${PG_ARCHIVE_ENTRY} not found`;
}
return checkPostgresDumpFile(dump, binDir);
}
/** Why the dump at `dump` cannot be restored into a Postgres database, or null: the checks of {@link checkPostgresDump}. */
async function checkPostgresDumpFile(dump: string, binDir: string | undefined): Promise<string | null> {
let executed: string[];
try {
executed = await pgDumpMigrations(dump, binDir);
@@ -107,6 +112,11 @@ export class PostgresDatabaseBackup implements DatabaseBackupStrategy {
if (refusal) throw new DomainError(400, refusal);
}
/** A kept copy must be a dump this build can restore: a SQLite file a switch of engine left behind is refused. */
checkCopy(file: string): Promise<string | null> {
return checkPostgresDumpFile(file, this.connection.binDir);
}
/** A dump of the database a restore is about to replace, in the data directory. */
keepCopyBeforeRestore(): Promise<string | null> {
const target = path.join(this.paths.dataDir, `pre-restore-${Date.now()}.pgdump`);