From 59f0c206bf19e12ab41dc4ffe64ede130a46102b Mon Sep 17 00:00:00 2001 From: Maurice Date: Tue, 17 Nov 2026 15:15:48 +0100 Subject: [PATCH] fix(db): match a stay's bookings by the stored '.0' text, as SQLite did Reading the TEXT column as an integer also matched '14', ' 14' and '14abc', which the legacy REAL-bound compare never did (AC37/AC40). Comparing with the '.0' text the services store keeps that contract on both engines. --- .../db/repositories/Reservations.repository.ts | 6 +++--- .../_shared/reservation-accommodation.ts | 16 +++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/server/src/db/repositories/Reservations.repository.ts b/server/src/db/repositories/Reservations.repository.ts index d2c1f7929..53cd7d6a2 100644 --- a/server/src/db/repositories/Reservations.repository.ts +++ b/server/src/db/repositories/Reservations.repository.ts @@ -609,7 +609,7 @@ export class ReservationsRepository extends TrekRepository { .else(concatKysely(platform, eb, { value: date }, { expression: substringKysely(platform, eb, 'reservation_time', 11) })) .end(), })) - .where((eb) => reservationStayIs(this.getEntityManager().getPlatform(), eb, 'accommodation_id', accommodation_id)) + .where((eb) => reservationStayIs(eb, 'accommodation_id', accommodation_id)) .where('type', '=', 'hotel') .execute(); } @@ -715,7 +715,7 @@ export class ReservationsRepository extends TrekRepository { const rows = await this.kysely() .selectFrom('reservations') .select(['id', 'metadata']) - .where((eb) => reservationStayIs(this.getEntityManager().getPlatform(), eb, 'accommodation_id', accommodation_id)) + .where((eb) => reservationStayIs(eb, 'accommodation_id', accommodation_id)) .execute(); return rows as { id: number; metadata: string | null }[]; } @@ -759,7 +759,7 @@ export class ReservationsRepository extends TrekRepository { const rows = await this.kysely() .selectFrom('reservations') .select(['id']) - .where((eb) => reservationStayIs(this.getEntityManager().getPlatform(), eb, 'accommodation_id', accommodation_id)) + .where((eb) => reservationStayIs(eb, 'accommodation_id', accommodation_id)) .execute(); return rows as { id: number }[]; } diff --git a/server/src/db/repositories/_shared/reservation-accommodation.ts b/server/src/db/repositories/_shared/reservation-accommodation.ts index 5dab7733c..1b46a7c6e 100644 --- a/server/src/db/repositories/_shared/reservation-accommodation.ts +++ b/server/src/db/repositories/_shared/reservation-accommodation.ts @@ -1,4 +1,5 @@ -import { castIntegerKysely, integerTextEqualsKysely } from '../../dialect/kysely-functions'; +import { legacyBoundIntegerText } from '../../../nest/common/row-id'; +import { integerTextEqualsKysely } from '../../dialect/kysely-functions'; import type { Platform } from '@mikro-orm/core'; import type { ExpressionBuilder, ExpressionWrapper, SqlBool, StringReference } from 'kysely'; @@ -24,16 +25,17 @@ export function accommodationIdMatches( /** * A reservation booked against the stay `stayId`, the filter form of - * {@link accommodationIdMatches}: the TEXT column read as an integer, so the - * stored `'14.0'` matches 14 on Postgres too. Compared as written (`= 14`), - * Postgres binds the number as the text `'14'` and finds no row at all, which - * no error reports. + * {@link accommodationIdMatches}, held to the legacy compare: SQLite bound the + * id as a REAL, so only the stored `'.0'` shape ever matched, never `'14'`, + * `' 14'` or `'14abc'` (Reservations.repository.test.ts AC37/AC40). Comparing + * the column with that same text keeps that on both engines. Compared with a + * bare number instead, Postgres binds it as the text `'14'` and finds no row + * at all, which no error reports. */ export function reservationStayIs( - platform: Platform, eb: ExpressionBuilder, accommodationId: StringReference, stayId: number, ): ExpressionWrapper { - return eb(castIntegerKysely(platform, eb, accommodationId), '=', stayId); + return eb(accommodationId, '=', legacyBoundIntegerText(stayId)); }