mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
fix(db): read unique violations and missing tables the same way on both engines
guardIdentity matched only SQLite's message text, so on Postgres a lost race for an email or a username escaped as a 500 instead of a 409. The new dialect module driver-errors.ts reads a unique violation by Postgres's SQLSTATE 23505 and constraint name, or by SQLite's message, and the users repository maps the key names of both engines. isMissingTableError moves there too and also knows Postgres's 42P01 for an unconverted error.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { columnNamesSql, tableExistsSql } from './dialect/catalog';
|
||||
import { forEngine, type EngineColumn, type EngineDdl } from './dialect/ddl';
|
||||
import { TableNotFoundException } from '@mikro-orm/core';
|
||||
import { isMissingTableError } from './dialect/driver-errors';
|
||||
import type { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
/**
|
||||
@@ -106,16 +106,6 @@ export async function execUnlessTableMissing(migration: Migration, sql: string,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True when a statement failed because its table does not exist. The ORM maps
|
||||
* SQLite's "no such table" and Postgres's SQLSTATE 42P01 to
|
||||
* `TableNotFoundException`; the raw SQLite message is checked too, for an error
|
||||
* that reached the caller unconverted.
|
||||
*/
|
||||
export function isMissingTableError(err: unknown): boolean {
|
||||
return err instanceof TableNotFoundException || (err instanceof Error && err.message.includes('no such table'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a group of statements the legacy step wrapped in a single swallowing
|
||||
* try/catch. A failure part-way through leaves the earlier statements applied,
|
||||
|
||||
Reference in New Issue
Block a user