d5279b124f
Storage Persistence Guard / storage-persistence-audit (push) Has been cancelled
Client Quality Gates / Shared client and Web (push) Has been cancelled
Client Quality Gates / macOS Desktop (push) Has been cancelled
Client Quality Gates / Shared client and Web (pull_request) Has been cancelled
Client Quality Gates / macOS Desktop (pull_request) Has been cancelled
Storage Persistence Guard / storage-persistence-audit (pull_request) Has been cancelled
34 lines
1.5 KiB
Python
34 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, String, func
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class UserLoginSession(Base):
|
|
"""Server-side login activity record without storing credentials."""
|
|
|
|
__tablename__ = "user_login_sessions"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True)
|
|
user_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
ForeignKey("users.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
client_type: Mapped[str] = mapped_column(String(16), nullable=False, default="web")
|
|
client_platform: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
|
client_version: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
client_source: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
|
login_ip: Mapped[str | None] = mapped_column(String(45), nullable=True)
|
|
login_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, server_default=func.now())
|
|
last_seen_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, server_default=func.now())
|
|
ended_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
end_reason: Mapped[str | None] = mapped_column(String(32), nullable=True)
|