From 6d36c2f9b10b9e23c74886e6425db9e4d24cf540 Mon Sep 17 00:00:00 2001 From: Melissa Autumn Date: Tue, 23 Apr 2024 13:01:44 -0700 Subject: [PATCH] Add a touch function to mdoels.Base. This updates the time_updated (does not save.) And force a touch update after schedule creation --- backend/src/appointment/database/models.py | 4 ++++ backend/src/appointment/database/repo.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/backend/src/appointment/database/models.py b/backend/src/appointment/database/models.py index fb7f184e0..e04d1c708 100644 --- a/backend/src/appointment/database/models.py +++ b/backend/src/appointment/database/models.py @@ -87,6 +87,10 @@ class Base: def __tablename__(cls): return cls.__name__.lower() + def touch(self): + """Updates the time_updated field with the current datetime. This function does not save the model!""" + self.time_updated = datetime.datetime.now() + time_created = Column(DateTime, server_default=func.now(), index=True) time_updated = Column(DateTime, server_default=func.now(), onupdate=func.now(), index=True) diff --git a/backend/src/appointment/database/repo.py b/backend/src/appointment/database/repo.py index 28285f0e1..3ff304a60 100644 --- a/backend/src/appointment/database/repo.py +++ b/backend/src/appointment/database/repo.py @@ -507,6 +507,13 @@ def create_calendar_schedule(db: Session, schedule: schemas.ScheduleBase): db.add(db_schedule) db.commit() db.refresh(db_schedule) + + # There's a bug on stage where onupdate isn't triggered on creates. + # So update the timestamp and commit it! + db_schedule.touch() + db.commit() + db.refresh(db_schedule) + return db_schedule