landvex: Fixar och tester klara för alla komponenter
- Datafabrik: Dockerfile fix, agentorkestrering fungerar - Vision: Identify-modell, FAISS, OCR alla testade - API: Alla 7 integrationstester passerade - Upplösare: Entitetsupplösning verifierad
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""Tenant model for multi-tenant isolation."""
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from sqlalchemy import String, JSON, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class TenantType(str, Enum):
|
||||
MUNICIPALITY = "municipality"
|
||||
ENTERPRISE = "enterprise"
|
||||
PARTNER = "partner"
|
||||
|
||||
|
||||
class TenantStatus(str, Enum):
|
||||
ACTIVE = "active"
|
||||
SUSPENDED = "suspended"
|
||||
CANCELLED = "cancelled"
|
||||
TRIAL = "trial"
|
||||
|
||||
|
||||
class Tenant(Base):
|
||||
__tablename__ = "tenants"
|
||||
|
||||
id: Mapped[UUID] = mapped_column(primary_key=True, default=uuid4)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
slug: Mapped[str] = mapped_column(String(100), unique=True, nullable=False)
|
||||
type: Mapped[TenantType] = mapped_column(nullable=False)
|
||||
org_number: Mapped[str | None] = mapped_column(String(20), unique=True)
|
||||
billing_email: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
plan_id: Mapped[UUID | None] = mapped_column(ForeignKey("subscription_plans.id"))
|
||||
status: Mapped[TenantStatus] = mapped_column(default=TenantStatus.ACTIVE)
|
||||
settings: Mapped[dict] = mapped_column(JSON, default=dict)
|
||||
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
default=datetime.utcnow, onupdate=datetime.utcnow
|
||||
)
|
||||
|
||||
# Relationships
|
||||
users: Mapped[list["User"]] = relationship(back_populates="tenant")
|
||||
api_keys: Mapped[list["ApiKey"]] = relationship(back_populates="tenant")
|
||||
invoices: Mapped[list["Invoice"]] = relationship(back_populates="tenant")
|
||||
audit_logs: Mapped[list["AuditLog"]] = relationship(back_populates="tenant")
|
||||
reports: Mapped[list["Report"]] = relationship(back_populates="tenant")
|
||||
installed_plugins: Mapped[list["TenantPlugin"]] = relationship(
|
||||
back_populates="tenant"
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Tenant {self.slug}>"
|
||||
Reference in New Issue
Block a user