Migration done

This commit is contained in:
Jonas Linter
2025-11-19 15:01:16 +01:00
parent 6c46c566ed
commit d88a53327f
4 changed files with 87 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ from typing import Optional
from sqlalchemy import and_, select
from sqlalchemy.ext.asyncio import AsyncSession
from .db import AckedRequest, Customer, Reservation
from .db import AckedRequest, Customer, HashedCustomer, Reservation
from .schemas import ReservationData
@@ -63,6 +63,19 @@ class ReservationService:
reservation = self._convert_reservation_data_to_db(
reservation_data, customer_id
)
# Automatically populate hashed_customer_id from the customer
# Since hashed_customer is always created when a customer is created,
# we can get it by querying for the hashed_customer with matching customer_id
hashed_customer_result = await self.session.execute(
select(HashedCustomer).where(
HashedCustomer.customer_id == customer_id
)
)
hashed_customer = hashed_customer_result.scalar_one_or_none()
if hashed_customer:
reservation.hashed_customer_id = hashed_customer.id
self.session.add(reservation)
if auto_commit: