7f7da15965
Completed: - Phase 0: Project Setup (T001-T003) - Docker Compose, FastAPI skeleton, React SPA - Phase 1: Auth System (T004-T008) - DB models, JWT auth, RBAC middleware, user management - Phase 2: Contacts & Tags (T009-T011) - CRUD API + UI - Phase 3: Equipment Catalog (T012-T014) - Models, API, UI with barcode/QR - Phase 4: Crew Management (T015-T017) - Models, availability, UI - Phase 5: Vehicle Fleet (T018-T020) - Models, assignments, UI - Phase 6: Projects (T021-T023) - Project hierarchy models, CRUD API, list/detail UI
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
"""User model."""
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import String, Boolean, DateTime, ForeignKey, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class User(Base):
|
|
"""Represents a user within a tenant account."""
|
|
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[str] = mapped_column(
|
|
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
|
|
)
|
|
account_id: Mapped[str] = mapped_column(
|
|
String(36), ForeignKey("accounts.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
|
|
full_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
role_id: Mapped[str | None] = mapped_column(
|
|
String(36), ForeignKey("roles.id", ondelete="SET NULL"), nullable=True
|
|
)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now(), nullable=False
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False
|
|
)
|
|
|
|
# Relationships
|
|
account: Mapped["Account"] = relationship("Account", back_populates="users")
|
|
role: Mapped["Role | None"] = relationship("Role", back_populates="users")
|