33 lines
1.6 KiB
Python
33 lines
1.6 KiB
Python
"""Workspace invitation model."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Any, Optional
|
|
|
|
from sqlalchemy import BigInteger, ForeignKey, Integer, TIMESTAMP, VARCHAR
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from .base import Base
|
|
from .types import JSONB
|
|
|
|
|
|
class TenantInvitation(Base):
|
|
__tablename__ = "tenant_invitations"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
email: Mapped[str] = mapped_column(VARCHAR(255), nullable=False, index=True)
|
|
phone_country_code: Mapped[Optional[str]] = mapped_column(VARCHAR(8), nullable=True)
|
|
phone_number: Mapped[Optional[str]] = mapped_column(VARCHAR(32), nullable=True)
|
|
phone_e164: Mapped[Optional[str]] = mapped_column(VARCHAR(32), nullable=True, index=True)
|
|
role: Mapped[str] = mapped_column(VARCHAR(50), nullable=False)
|
|
project_ids: Mapped[Any] = mapped_column(JSONB, nullable=False, default=list)
|
|
token_hash: Mapped[str] = mapped_column(VARCHAR(128), nullable=False, unique=True, index=True)
|
|
status: Mapped[str] = mapped_column(VARCHAR(32), nullable=False, default="pending")
|
|
expires_at: Mapped[datetime] = mapped_column(TIMESTAMP, nullable=False)
|
|
invited_by_user_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("users.id"), nullable=False)
|
|
accepted_by_user_id: Mapped[Optional[int]] = mapped_column(BigInteger, ForeignKey("users.id"), nullable=True)
|
|
|
|
invited_by = relationship("User", foreign_keys=[invited_by_user_id])
|
|
accepted_by = relationship("User", foreign_keys=[accepted_by_user_id])
|