File size: 2,022 Bytes
e2800b3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | import uuid
from datetime import datetime
from sqlalchemy import Boolean, DateTime, Index, String, func
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column
from app.db.base import Base
class User(Base):
__tablename__ = "users"
id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
primary_key=True,
default=uuid.uuid4,
)
full_name: Mapped[str] = mapped_column(
String(150),
nullable=False,
)
email: Mapped[str] = mapped_column(
String(320),
nullable=False,
unique=True,
)
password_hash: Mapped[str] = mapped_column(
String(255),
nullable=False,
)
country_code: Mapped[str | None] = mapped_column(
String(2),
nullable=True,
)
preferred_language: Mapped[str] = mapped_column(
String(5),
nullable=False,
default="fr",
server_default="fr",
)
role: Mapped[str] = mapped_column(
String(30),
nullable=False,
default="user",
server_default="user",
)
is_active: Mapped[bool] = mapped_column(
Boolean,
nullable=False,
default=True,
server_default="true",
)
is_email_verified: Mapped[bool] = mapped_column(
Boolean,
nullable=False,
default=False,
server_default="false",
)
onboarding_completed: Mapped[bool] = mapped_column(
Boolean,
nullable=False,
default=False,
server_default="false",
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
server_default=func.now(),
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
server_default=func.now(),
onupdate=func.now(),
)
__table_args__ = (
Index("ix_users_email", "email"),
Index("ix_users_role", "role"),
) |