service_man/api/infrastructure/persistence/models/company.py

58 lines
1.5 KiB
Python
Raw Permalink Normal View History

2024-04-10 00:33:31 +03:00
import uuid
2024-04-21 23:46:17 +03:00
from sqlalchemy import UUID, ForeignKey
2024-04-10 00:33:31 +03:00
from sqlalchemy.orm import Mapped, mapped_column
from api.infrastructure.persistence.models.base import Base
class CompanyModel(Base):
2024-04-21 23:46:17 +03:00
__tablename__ = "company"
2024-04-10 00:33:31 +03:00
id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
primary_key=True,
)
name: Mapped[str]
email: Mapped[str] = mapped_column(unique=True)
2024-04-21 23:46:17 +03:00
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]
2024-04-23 12:08:56 +03:00
company_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("company.id", ondelete="CASCADE"))
2024-04-21 23:46:17 +03:00
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,
)