Files
python-api/app/models/mariadb/user.py
2026-03-01 07:44:19 +09:00

45 lines
1.5 KiB
Python

from __future__ import annotations
from datetime import datetime
from sqlmodel import Field, Relationship, SQLModel
from app.core.constants import Role
from app.db.base import SoftDeleteMixin, TimestampMixin
class User(TimestampMixin, SoftDeleteMixin, SQLModel, table=True):
__tablename__ = "users"
id: int | None = Field(default=None, primary_key=True)
email: str = Field(max_length=255, unique=True, index=True)
hashed_password: str = Field(max_length=255)
role: str = Field(default=Role.USER, max_length=20)
is_active: bool = Field(default=True)
is_verified: bool = Field(default=False)
last_login_at: datetime | None = Field(default=None)
# Relationships
profile: UserProfile | None = Relationship(back_populates="user")
refresh_tokens: list[RefreshToken] = Relationship(back_populates="user")
class UserProfile(TimestampMixin, SQLModel, table=True):
__tablename__ = "user_profiles"
id: int | None = Field(default=None, primary_key=True)
user_id: int = Field(foreign_key="users.id", unique=True, index=True)
full_name: str = Field(default="", max_length=100)
phone: str = Field(default="", max_length=20)
organization: str = Field(default="", max_length=100)
avatar_url: str = Field(default="", max_length=500)
# Relationships
user: User | None = Relationship(back_populates="profile")
# Forward reference resolution
from app.models.mariadb.auth import RefreshToken # noqa: E402
User.model_rebuild()