import uuid from sqlalchemy import UUID, ForeignKey from sqlalchemy.orm import Mapped, mapped_column from api.infrastructure.persistence.models.base import Base class CompanyModel(Base): __tablename__ = "company" id: Mapped[uuid.UUID] = mapped_column( UUID(as_uuid=True), primary_key=True, ) name: Mapped[str] email: Mapped[str] = mapped_column(unique=True) address: Mapped[str] owner_id: Mapped[uuid.UUID] = mapped_column( ForeignKey("users.id", ondelete="CASCADE"), ) class DepartmentModel(Base): __tablename__ = "department" id: Mapped[uuid.UUID] = mapped_column( UUID(as_uuid=True), primary_key=True, ) name: Mapped[str] address: Mapped[str] company_id: Mapped[uuid.UUID] = mapped_column( ForeignKey("company.id", ondelete="CASCADE") ) class CompanyDepartmentModel(Base): __tablename__ = "company_department_m2m" company_id: Mapped[uuid.UUID] = mapped_column( ForeignKey("company.id", ondelete="CASCADE"), primary_key=True, ) department_id: Mapped[uuid.UUID] = mapped_column( ForeignKey("department.id", ondelete="CASCADE"), primary_key=True, ) class DepartmentUserModel(Base): __tablename__ = "department_user_m2m" department_id: Mapped[uuid.UUID] = mapped_column( ForeignKey("department.id", ondelete="CASCADE"), primary_key=True, ) user_id: Mapped[uuid.UUID] = mapped_column( ForeignKey("users.id"), primary_key=True, )