feat(db): keep SQLite's write and search semantics on Postgres

- UnitOfWork transactions take one advisory lock for the database on
  Postgres (DatabaseEngine.serializeWrites, pg_advisory_xact_lock), so a
  MAX(...) + 1 read inside one cannot race another, as with SQLite's single
  writer. SQLite needs nothing.
- ilike(platform, refs) builds the case-insensitive search condition: LIKE
  on SQLite, ILIKE on Postgres, where LIKE is exact. The place searches use it.
- Plugin data erasure runs each statement in its own savepoint: on Postgres a
  failed statement would abort the user's whole erasure transaction.
This commit is contained in:
Isaias Tavares
2026-11-02 14:58:29 -03:00
parent a77705984e
commit 515caffa79
13 changed files with 98 additions and 15 deletions
@@ -3,6 +3,7 @@ import { resolveDbPath } from '../../db-path';
import { runSchemaBootstrap, type AnyOrm } from '../../orm';
import { SharedSqliteDriver } from '../../orm-driver';
import type { DatabaseEngine } from '../engine';
import type { EntityManager } from '@mikro-orm/core';
/**
* The SQLite file engine, TREK's default: one better-sqlite3 handle that
@@ -40,4 +41,9 @@ export class SqliteEngine implements DatabaseEngine {
schemaBootstrap(orm: AnyOrm, options: { snapshot: boolean }): Promise<void> {
return runSchemaBootstrap(orm, options);
}
serializeWrites(_em: EntityManager): Promise<void> {
// One connection, one writer: SQLite serializes the transactions already.
return Promise.resolve();
}
}