Skip to content

Commit

Permalink
Add a touch function to mdoels.Base. This updates the time_updated (d…
Browse files Browse the repository at this point in the history
…oes not save.) And force a touch update after schedule creation
  • Loading branch information
MelissaAutumn authored and jdbass committed May 17, 2024
1 parent 85247c5 commit 6d36c2f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/src/appointment/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions backend/src/appointment/database/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 6d36c2f

Please sign in to comment.