mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
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:
@@ -1,5 +1,5 @@
|
||||
import type { AnyOrm } from '../orm';
|
||||
import type { Options } from '@mikro-orm/core';
|
||||
import type { EntityManager, Options } from '@mikro-orm/core';
|
||||
|
||||
/** The databases TREK can be pointed at. MySQL/MariaDB are out of scope (server/CLAUDE.md). */
|
||||
type EngineId = 'sqlite' | 'postgres';
|
||||
@@ -37,4 +37,10 @@ export interface DatabaseEngine {
|
||||
* archive is the copy).
|
||||
*/
|
||||
schemaBootstrap(orm: AnyOrm, options: { snapshot: boolean }): Promise<void>;
|
||||
/**
|
||||
* Runs first in every `UnitOfWork` transaction, on its EntityManager: makes
|
||||
* the transactions that write run one at a time, as SQLite's single writer
|
||||
* does, so a `MAX(...) + 1` read inside one cannot race another.
|
||||
*/
|
||||
serializeWrites(em: EntityManager): Promise<void>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user