openvpn-endpoint-server/server/app/models/tenant.py

29 lines
1.2 KiB
Python

"""Tenant model for multi-tenant support."""
from datetime import datetime
from sqlalchemy import Column, Integer, String, Boolean, DateTime, Text
from sqlalchemy.orm import relationship
from ..database import Base
class Tenant(Base):
"""Tenant/Customer model for multi-tenant separation."""
__tablename__ = "tenants"
id = Column(Integer, primary_key=True, index=True)
name = Column(String(255), nullable=False, unique=True)
description = Column(Text, nullable=True)
is_active = Column(Boolean, default=True, nullable=False)
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Relationships
users = relationship("User", back_populates="tenant", cascade="all, delete-orphan")
gateways = relationship("Gateway", back_populates="tenant", cascade="all, delete-orphan")
certificate_authorities = relationship("CertificateAuthority", back_populates="tenant", cascade="all, delete-orphan")
vpn_servers = relationship("VPNServer", back_populates="tenant", cascade="all, delete-orphan")
def __repr__(self):
return f"<Tenant(id={self.id}, name='{self.name}')>"