fix(db): run every repository statement the Postgres probe reaches

The probe's baseline is empty now: no repository method Postgres refuses,
none it cannot measure.

- reservations.accommodation_id (TEXT) is cast where it is compared with
  day_accommodations.id (INTEGER), in the four reservation reads and the two
  stay reads; SQLite coerced the bare comparison, Postgres refuses it. The
  joined RS18/RR1 read moves to reservation-join.ts beside the repository.
- The usage counters qualify the target row's column in DO UPDATE SET, which
  Postgres reads as ambiguous with `excluded` otherwise.
- ReservationDayPositions.upsertScoped upserts on its primary key instead of
  INSERT OR REPLACE; position is the only other column and nothing references
  the table, so the row left behind is the same.
- PRAGMA wal_checkpoint and VACUUM INTO move from MaintenanceRepository to
  SqliteMaintenance under src/db/engine/sqlite/, the SQLite engine's folder,
  where lint:dialect allows PRAGMA.
- The places list takes category and tag ids as numbers: the service converts
  the query text with toRowId and answers an empty list for one that is no
  id, instead of binding the text to an integer column.
- The probe samples the `present` flag of a partial update's pair as true, so
  the four update methods that sent no SQL are measured, and it now holds
  SQLSTATE class 22 too: a value of the wrong type reaching a column is the
  code's, since the sampler sends what each parameter declares.
This commit is contained in:
Isaias Tavares
2026-11-02 12:48:08 -03:00
parent 14c767a675
commit 62912e5db1
36 changed files with 475 additions and 274 deletions
@@ -2,12 +2,12 @@
* SqliteDatabaseBackup: the database backup port for a SQLite file.
*
* The snapshot and the swap run for real here, against a database file in a
* temp directory: a VACUUM INTO through the real MaintenanceRepository, and the
* temp directory: a VACUUM INTO through the real SqliteMaintenance, and the
* copy, sidecar removal and rename of a restore. Only the connection lifecycle
* is a stand-in, because closing and reopening the process's own connection is
* DatabaseLifecycle's business (tests/unit/nest/database/).
*/
import { MaintenanceRepository } from '../../../src/db/repositories/MaintenanceRepository';
import { SqliteMaintenance } from '../../../src/db/engine/sqlite/sqlite-maintenance';
import { SqliteDatabaseBackup } from '../../../src/nest/backup/sqlite-database-backup';
import { DatabaseConnectionLostError } from '../../../src/nest/database/database-backup.interface';
import type { DatabaseLifecycle } from '../../../src/nest/database/database-lifecycle.service';
@@ -40,7 +40,7 @@ function maintenanceStub() {
function portWith(maintenance: { walCheckpoint: unknown; vacuumInto: unknown }): SqliteDatabaseBackup {
return new SqliteDatabaseBackup(
lifecycle as unknown as DatabaseLifecycle,
maintenance as unknown as MaintenanceRepository,
maintenance as unknown as SqliteMaintenance,
);
}
@@ -116,7 +116,7 @@ describe('SqliteDatabaseBackup', () => {
// test-sql-allow: the marker table is a bare fixture no entity maps; the write has to land in the WAL of this file.
live.prepare('UPDATE marker SET label = ?').run('after');
const target = path.join(dir, 'copy.db');
const port = portWith(new MaintenanceRepository(orm.em));
const port = portWith(new SqliteMaintenance(orm.em));
await withRequestContext(orm.orm, () => port.snapshot(target));
@@ -125,7 +125,7 @@ describe('SqliteDatabaseBackup', () => {
it('SQLBK-005: a VACUUM INTO that fails rejects and leaves nothing at the target', async () => {
const target = path.join(dir, 'missing-dir', 'copy.db');
const port = portWith(new MaintenanceRepository(orm.em));
const port = portWith(new SqliteMaintenance(orm.em));
await expect(withRequestContext(orm.orm, () => port.snapshot(target))).rejects.toThrow();