22 lines
837 B
Python
22 lines
837 B
Python
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import CheckConstraint, DateTime, Text, Uuid, text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from models.base import Base
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
__table_args__ = (
|
|
CheckConstraint("username ~ '^[a-z0-9_]{3,32}$'", name="username_format"),
|
|
CheckConstraint("char_length(display_name) BETWEEN 1 AND 100", name="display_name_len"),
|
|
)
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()"))
|
|
username: Mapped[str] = mapped_column(Text, unique=True)
|
|
display_name: Mapped[str] = mapped_column(Text)
|
|
password_hash: Mapped[str] = mapped_column(Text)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=text("clock_timestamp()"))
|