Skip to content

Commit

Permalink
Add tenant model
Browse files Browse the repository at this point in the history
  • Loading branch information
shri committed Jul 25, 2024
1 parent 84b64cd commit 85002bd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/app/db/models/tenant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from advanced_alchemy.base import SlugKey, UUIDAuditBase
from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column, relationship

if TYPE_CHECKING:
from .user import User


class Tenant(UUIDAuditBase, SlugKey):
"""A group of tenants i.e. a company or an organization."""

__tablename__ = "tenant"
__pii_columns__ = {"name", "description", "url"}
name: Mapped[str] = mapped_column(nullable=False, index=True)
description: Mapped[str | None] = mapped_column(String(length=500), nullable=True, default=None)
url: Mapped[str | None] = mapped_column(nullable=True, default=None)
is_active: Mapped[bool] = mapped_column(default=True, nullable=False)
# -----------
# ORM Relationships
# ------------
users: Mapped[list[User]] = relationship(
back_populates="tenant",
innerjoin=True,
lazy="selectin",
)

0 comments on commit 85002bd

Please sign in to comment.