41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import enum
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, Enum, ForeignKey, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class UserRole(str, enum.Enum):
|
|
user = "user"
|
|
admin = "admin"
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, index=True)
|
|
username: Mapped[str] = mapped_column(String(100), unique=True, index=True)
|
|
hashed_password: Mapped[str] = mapped_column(String(255))
|
|
role: Mapped[UserRole] = mapped_column(Enum(UserRole), default=UserRole.user)
|
|
is_active: Mapped[bool] = mapped_column(default=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
|
|
|
templates = relationship(
|
|
"DocumentTemplate",
|
|
back_populates="owner",
|
|
cascade="all, delete-orphan",
|
|
)
|
|
documents = relationship(
|
|
"FilledDocument",
|
|
back_populates="owner",
|
|
cascade="all, delete-orphan",
|
|
)
|
|
verification_tokens = relationship(
|
|
"VerificationToken",
|
|
back_populates="user",
|
|
cascade="all, delete-orphan",
|
|
)
|