-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase_models.py
More file actions
27 lines (21 loc) · 851 Bytes
/
database_models.py
File metadata and controls
27 lines (21 loc) · 851 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
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from sqlalchemy import DateTime, BIGINT, Integer, Text
from datetime import datetime
from zoneinfo import ZoneInfo
def utc_now():
return datetime.now(ZoneInfo("UTC"))
class TableModel(DeclarativeBase):
pass
class HabitOrm(TableModel):
__tablename__ = "habit"
__table_args__ = {"schema": "public"}
id: Mapped[int] = mapped_column(BIGINT, primary_key=True, autoincrement=True)
user_id: Mapped[int]
name: Mapped[str]
description: Mapped[str | None]
class CompletionOrm(TableModel):
__tablename__ = "completion"
__table_args__ = {"schema": "public"}
id: Mapped[int] = mapped_column(BIGINT, primary_key=True, autoincrement=True)
habit_id: Mapped[int]
date: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)