Skip to content

Commit fdd9c5f

Browse files
committed
fix: forces the DB to calculate the default current time
1 parent 30b3a77 commit fdd9c5f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/auth/tables.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datetime import datetime
2-
from typing import Any
32

4-
from sqlalchemy import DateTime, ForeignKey, String, Text
3+
from sqlalchemy import DateTime, ForeignKey, String, Text, func
54
from sqlalchemy.orm import Mapped, mapped_column
65

76
from constants import COMPUTING_ID_LEN, SESSION_ID_LEN
@@ -18,8 +17,9 @@ class UserSession(Base):
1817
primary_key=True,
1918
)
2019

20+
# TODO: Make all timestamps uneditable later
2121
# time the CAS ticket was issued
22-
issue_time: Mapped[datetime] = mapped_column(DateTime, nullable=False)
22+
issue_time: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.now())
2323

2424
session_id: Mapped[str] = mapped_column(
2525
String(SESSION_ID_LEN), nullable=False, unique=True
@@ -37,9 +37,8 @@ class SiteUser(Base):
3737
)
3838

3939
# first and last time logged into the CSSS API
40-
# note: default date (for pre-existing columns) is June 16th, 2024
41-
first_logged_in: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime(2024, 6, 16))
42-
last_logged_in: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime(2024, 6, 16))
40+
first_logged_in: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.now())
41+
last_logged_in: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.now())
4342

4443
# optional user information for display purposes
4544
profile_picture_url: Mapped[str | None] = mapped_column(Text, nullable=True)

0 commit comments

Comments
 (0)