fix(demo): save the first baseline after a reopen that seeded too

The demo seed runs in the schema bootstrap, at boot and again after every
reopen. Since the baseline save moved out of the seed into DemoResetJob,
only the boot read the seed's mark. A restore onto a demo instance with no
baseline, whose archive held no admin trips, seeded the example trips
during the reopen and then saved nothing, so the hourly reset kept logging
"No baseline found"; the mark also stayed set for the rest of the process.
Before the move, that path saved the baseline from inside the seed.

DatabaseLifecycle now runs listeners after a reopen's schema bootstrap,
and DemoResetJob registers one in demo mode that does the same check as at
boot: save through the backup port when the seed just ran and no baseline
exists. Each check clears the mark. A failed save is logged, never turned
into a failed reopen. AdminModule imports DatabaseLifecycleModule from the
shared database kernel for it.
This commit is contained in:
Maurice
2026-10-08 15:48:38 +02:00
parent 1dfc5dd8ea
commit 3e1234112d
9 changed files with 149 additions and 18 deletions
@@ -84,6 +84,42 @@ describe('DatabaseLifecycle', () => {
expect(calls).toEqual(['connection.close:true', 'connection.connect', 'runSchemaBootstrap:{"snapshot":false}']);
});
it('DBLIFE-007: listeners registered with onReopened run after the schema bootstrap of a reopen, in order', async () => {
const { orm } = ormStub();
const lifecycle = new DatabaseLifecycle(orm);
lifecycle.onReopened(async () => {
calls.push('listener:first');
});
lifecycle.onReopened(async () => {
calls.push('listener:second');
});
await lifecycle.open();
const hook = dbMock.registerReinitializeHook.mock.calls[0][0];
calls.length = 0;
await hook();
expect(calls).toEqual([
'connection.close:true',
'connection.connect',
'runSchemaBootstrap:{"snapshot":false}',
'listener:first',
'listener:second',
]);
});
it('DBLIFE-008: a listener that throws fails the reopen, so a listener must contain its own failures', async () => {
const { orm } = ormStub();
const lifecycle = new DatabaseLifecycle(orm);
lifecycle.onReopened(async () => {
throw new Error('listener broke');
});
await lifecycle.open();
const hook = dbMock.registerReinitializeHook.mock.calls[0][0];
await expect(hook()).rejects.toThrow('listener broke');
});
it('DBLIFE-003: close() and reopen() go through the connection module', async () => {
const lifecycle = new DatabaseLifecycle(ormStub().orm);