Add initial project files
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
0
backend/app/models/__init__.py
Normal file
0
backend/app/models/__init__.py
Normal file
28
backend/app/models/entry.py
Normal file
28
backend/app/models/entry.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from datetime import datetime, date
|
||||
from typing import Optional
|
||||
from sqlalchemy import String, Text, Float, Date, DateTime, ForeignKey, Enum, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
import enum
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class EntryType(str, enum.Enum):
|
||||
add = "add"
|
||||
remove = "remove"
|
||||
|
||||
|
||||
class Entry(Base):
|
||||
__tablename__ = "entries"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False, index=True)
|
||||
entry_type: Mapped[EntryType] = mapped_column(Enum(EntryType), nullable=False)
|
||||
date: Mapped[date] = mapped_column(Date, nullable=False)
|
||||
bourbon_name: Mapped[Optional[str]] = mapped_column(String(255))
|
||||
proof: Mapped[Optional[float]] = mapped_column(Float)
|
||||
amount_shots: Mapped[float] = mapped_column(Float, nullable=False, default=1.0)
|
||||
notes: Mapped[Optional[str]] = mapped_column(Text)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
||||
|
||||
user: Mapped["User"] = relationship("User", back_populates="entries")
|
||||
19
backend/app/models/user.py
Normal file
19
backend/app/models/user.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from sqlalchemy import String, DateTime, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False, index=True)
|
||||
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
display_name: Mapped[Optional[str]] = mapped_column(String(100))
|
||||
timezone: Mapped[str] = mapped_column(String(50), default="UTC")
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
||||
|
||||
entries: Mapped[list["Entry"]] = relationship("Entry", back_populates="user", cascade="all, delete-orphan")
|
||||
Reference in New Issue
Block a user