-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase_models.py
More file actions
32 lines (23 loc) · 1021 Bytes
/
database_models.py
File metadata and controls
32 lines (23 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from sqlalchemy import DateTime, BIGINT, ForeignKey
from datetime import datetime
from zoneinfo import ZoneInfo
def utc_now() -> datetime:
return datetime.now(ZoneInfo("UTC"))
class TableModel(DeclarativeBase):
pass
class RoomORM(TableModel):
__tablename__ = "room"
__table_args__ = {"schema": "public"}
id: Mapped[int] = mapped_column(BIGINT, primary_key=True, autoincrement=True)
name: Mapped[str]
capacity: Mapped[int]
location: Mapped[str]
class BookingORM(TableModel):
__tablename__ = "booking"
__table_args__ = {"schema": "public"}
id: Mapped[int] = mapped_column(BIGINT, primary_key=True, autoincrement=True)
room_id: Mapped[int] = mapped_column(BIGINT, ForeignKey("public.room.id"))
user_name: Mapped[str]
start_time: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
end_time: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)