File size: 1,557 Bytes
b7bf9e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
User model for the sorted todo application.

Represents an application user managed by Better Auth.
"""

import uuid
from datetime import datetime

from sqlalchemy import Boolean, Column, String
from sqlmodel import Field, SQLModel

from src.api.models.types import GUID


class User(SQLModel, table=True):
    """
    User entity representing an application user.

    Schema matches Better Auth's expected user table structure.
    Better Auth manages user creation via its sign-up flow.

    Attributes:
        id: UUID primary key
        name: User display name (required by Better Auth)
        email: Unique email address for authentication
        email_verified: Whether the user's email has been verified
        image: Optional profile image URL
        created_at: Account creation timestamp
        updated_at: Last update timestamp
    """

    __tablename__ = "users"

    id: uuid.UUID = Field(
        default_factory=uuid.uuid4,
        sa_column=Column(GUID, primary_key=True),
    )
    name: str = Field(sa_column=Column(String(255), nullable=False, default=""))
    email: str = Field(
        sa_column=Column(String(255), unique=True, nullable=False, index=True)
    )
    email_verified: bool = Field(
        sa_column=Column(Boolean, nullable=False, default=False)
    )
    image: str | None = Field(default=None, sa_column=Column(String(500), nullable=True))
    created_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)
    updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)