refactor(scheduling): take a cron lease in one conditional upsert

acquire() made sure a row existed and then raced on a conditional UPDATE,
two statements the registrar wrapped in a transaction of its own. lint:tx
cannot follow a repository reached through a local variable, so it
reported the method. One INSERT ... ON CONFLICT DO UPDATE ... WHERE now
takes a free lease, renews the holder's and leaves anyone else's alone,
atomically on SQLite and on Postgres, and needs no transaction.
This commit is contained in:
Maurice
2026-10-08 19:05:03 +02:00
parent fac139723e
commit 68504b337f
4 changed files with 22 additions and 26 deletions
@@ -6,6 +6,7 @@
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
import { createSnapshotTestDb } from '../../../helpers/db-mock';
import { createTestOrm, type TestOrm } from '../../../helpers/test-orm';
import { deleteRows } from '../../../helpers/factories/rows';
import { SchedulerLeases } from '../../../../src/db/entities/SchedulerLeases.entity';
import type { SchedulerLeasesRepository } from '../../../../src/db/repositories/SchedulerLeases.repository';
@@ -17,8 +18,8 @@ beforeAll(async () => {
t = await createTestOrm(testDb);
leases = t.repo(SchedulerLeases);
});
beforeEach(() => {
testDb.prepare('DELETE FROM scheduler_leases').run();
beforeEach(async () => {
await deleteRows(t, SchedulerLeases);
t.clear();
});
afterAll(async () => {