- Updated GBultoService to use models.Package instead of models.GBulto. - Refactored Part model to use SQLAlchemy 2.0 style with Mapped and mapped_column. - Added timestamps (created_at, updated_at, deleted_at) to various pedimento models. - Improved relationships and foreign key constraints in pedimento models. - Updated PermissionRuleOct and Seal models to use Mapped and mapped_column. - Changed DTO configuration from orm_mode to from_attributes for better compatibility. - Removed obsolete models (models.py and models_ped.py) from the repository.
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
"""
|
|
Modelos ORM para gestión de tenants
|
|
"""
|
|
from sqlalchemy import Column, Integer, String, DateTime, Boolean, Text, Enum as SQLEnum
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
from datetime import datetime
|
|
from core.database import Base
|
|
import enum
|
|
|
|
|
|
class TenantType(enum.Enum):
|
|
"""Tipo de tenant según tamaño y necesidades"""
|
|
SHARED = "shared" # BD compartida
|
|
DEDICATED = "dedicated" # BD dedicada
|
|
|
|
|
|
class Tenant(Base):
|
|
"""
|
|
Modelo de Tenant - Cliente/Organización en el sistema
|
|
Cada tenant puede tener BD compartida o dedicada
|
|
"""
|
|
__tablename__ = "tenants"
|
|
__table_args__ = {"schema": "a76"}
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String(255), nullable=False, index=True)
|
|
slug = Column(String(100), unique=True, nullable=False, index=True)
|
|
|
|
# Tipo de tenant (compartido o dedicado)
|
|
type = Column(SQLEnum(TenantType), default=TenantType.SHARED, nullable=False)
|
|
|
|
# Keycloak realm asociado
|
|
keycloak_realm = Column(String(255), unique=True, nullable=False)
|
|
|
|
# Configuración de BD dedicada (JSON string o NULL si usa BD compartida)
|
|
db_config = Column(Text, nullable=True) # JSON: {host, port, name, user, password}
|
|
|
|
# Información de contacto
|
|
contact_name = Column(String(255))
|
|
contact_email = Column(String(255))
|
|
contact_phone = Column(String(50))
|
|
|
|
# Estado
|
|
is_active = Column(Boolean, default=True, nullable=False)
|
|
|
|
# Timestamps
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=func.now(), onupdate=func.now())
|
|
deleted_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
|
|
def __repr__(self):
|
|
return f"<Tenant(id={self.id}, name={self.name}, type={self.type.value})>"
|