(ex: UniqueCheckExecutor)
| 472 | // inside the caller's would be the nested pool checkout the migration- |
| 473 | // hardening work eliminated (self-deadlock under pool exhaustion). |
| 474 | const checkConditions = async (ex: UniqueCheckExecutor) => { |
| 475 | for (const condition of conditions) { |
| 476 | const baseCondition = and(eq(userTableRows.tableId, tableId), condition.sql) |
| 477 | |
| 478 | const whereClause = excludeRowId |
| 479 | ? and(baseCondition, sql`${userTableRows.id} != ${excludeRowId}`) |
| 480 | : baseCondition |
| 481 | |
| 482 | const conflictingRow = await ex |
| 483 | .select({ id: userTableRows.id, position: userTableRows.position }) |
| 484 | .from(userTableRows) |
| 485 | .where(whereClause) |
| 486 | .limit(1) |
| 487 | |
| 488 | if (conflictingRow.length > 0) { |
| 489 | errors.push( |
| 490 | `Column "${condition.column.name}" must be unique. Value "${condition.value}" already exists in row ${conflictingRow[0].position + 1}` |
| 491 | ) |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | if (executor === db) { |
| 497 | await withSeqscanOff(async (trx) => checkConditions(trx)) |
no test coverage detected