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
+13
View File
@@ -44,6 +44,7 @@ import {
dateOf,
dayDistance,
foundAgainState,
ilike,
lower,
lowerParam,
lowerTrim,
@@ -269,6 +270,18 @@ export const HELPER_CASES: readonly HelperCase[] = [
raw: (p) => rawOf(dayDistance(p, 'a', '2026-09-24')),
expect: { equals: 3 },
},
{
name: 'ilike matches in other case',
row: { a: 'Probe Place' },
raw: (p) => ({ sql: ilike(p, ['a']), params: ['%PLACE%'] }),
expect: { equals: true },
},
{
name: 'ilike keeps the escaped wildcard literal',
row: { a: 'Probe Place' },
raw: (p) => ({ sql: ilike(p, ['a']), params: ['probe\\_place'] }),
expect: { equals: false },
},
{
name: 'collateNoCase',
row: { a: 'Probe' },
+1 -1
View File
@@ -1,7 +1,7 @@
{
"scripts/db-call-graph.mjs": 1036,
"scripts/generate-entities.ts": 2259,
"src/db/repositories/Places.repository.ts": 1437,
"src/db/repositories/Places.repository.ts": 1435,
"src/db/repositories/Reservations.repository.ts": 1563,
"src/db/repositories/Trips.repository.ts": 1121,
"src/db/repositories/Users.repository.ts": 1445,