26 lines
1021 B
Python
26 lines
1021 B
Python
"""用户模型。"""
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import Boolean, DateTime, String
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.ids import new_user_id
|
|
from app.core.time import utc_now
|
|
from app.db.base import Base
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[str] = mapped_column(String(40), primary_key=True, default=new_user_id)
|
|
username: Mapped[str] = mapped_column(String(80), unique=True, nullable=False, index=True)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
|
|
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
|
is_admin: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=utc_now, onupdate=utc_now
|
|
)
|