fix(db): pin the tenant scope to one connection (coreci-chat#14)
ci / test-pglite (PGlite, default) (push) Failing after 1m50s
ci / test-postgres (Postgres 16, G-022 RLS) (push) Failing after 1m33s
ci / test-pglite (PGlite, default) (pull_request) Failing after 1m50s
ci / test-postgres (Postgres 16, G-022 RLS) (pull_request) Failing after 1m35s

This commit is contained in:
2026-10-27 08:31:45 +00:00
parent db158255c0
commit d9da54b3bf
+10
View File
@@ -16,4 +16,14 @@ export interface DbClient {
query<T = Record<string, unknown>>(text: string, params?: unknown[]): Promise<QueryResult<T>>;
/** Run multi-statement SQL (DDL, migrations). No params. Use for migrations only. */
exec(text: string): Promise<void>;
/**
* Run `fn` inside one transaction on ONE connection.
*
* A pooled client can hand out a different connection per statement, so a
* transaction-local setting (the tenant scope `SET LOCAL app.tenant_id`)
* only holds if every statement of the transaction shares a connection.
* Optional: a client that cannot pin a connection omits it, and withTenant
* keeps its own BEGIN/COMMIT path as the fallback.
*/
transaction?<T>(fn: (client: DbClient) => Promise<T>): Promise<T>;
}