27 lines
904 B
Python
27 lines
904 B
Python
"""用户-项目关联模型。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import BigInteger, Integer, ForeignKey, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from .base import Base
|
|
|
|
|
|
class UserProject(Base):
|
|
__tablename__ = "user_projects"
|
|
__table_args__ = (
|
|
UniqueConstraint("tenant_id", "user_id", "project_id", name="uq_user_projects_tenant_user_project"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(
|
|
BigInteger, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True
|
|
)
|
|
project_id: Mapped[int] = mapped_column(
|
|
BigInteger, ForeignKey("projects.id", ondelete="CASCADE"), nullable=False, index=True
|
|
)
|
|
|
|
user = relationship("User", back_populates="project_links")
|
|
project = relationship("Project")
|