- Implemented SvelteKit frontend with authentication callback handling. - Created demo routes and paraglide localization functionality. - Added health check and entrypoint scripts for backend services. - Established PostgreSQL and Keycloak initialization scripts with health checks. - Introduced models for database schema using SQLAlchemy. - Configured Vite and SvelteKit for development and testing environments. - Added health check script to verify service statuses and resource usage. - Created Docker entrypoint scripts for seamless service startup.
90 lines
3.1 KiB
Python
90 lines
3.1 KiB
Python
"""
|
|
Modelos ORM para gestión de licencias
|
|
"""
|
|
from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey, Enum as SQLEnum
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from core.database import Base
|
|
import enum
|
|
|
|
|
|
class LicensePlan(enum.Enum):
|
|
"""Planes de licencia disponibles"""
|
|
FREE = "free"
|
|
BASIC = "basic"
|
|
PROFESSIONAL = "professional"
|
|
ENTERPRISE = "enterprise"
|
|
|
|
|
|
class LicenseStatus(enum.Enum):
|
|
"""Estados de licencia"""
|
|
ACTIVE = "active"
|
|
EXPIRED = "expired"
|
|
SUSPENDED = "suspended"
|
|
PENDING = "pending"
|
|
CANCELLED = "cancelled"
|
|
|
|
|
|
class License(Base):
|
|
"""
|
|
Modelo de Licencia - Control de planes y límites por tenant
|
|
"""
|
|
__tablename__ = "licenses"
|
|
__table_args__ = {"schema": "a76"}
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
tenant_id = Column(Integer, ForeignKey("a76.tenants.id"), nullable=False, unique=True, index=True)
|
|
|
|
# Plan y características
|
|
plan = Column(SQLEnum(LicensePlan), default=LicensePlan.FREE, nullable=False)
|
|
status = Column(SQLEnum(LicenseStatus), default=LicenseStatus.PENDING, nullable=False)
|
|
|
|
# Límites del plan
|
|
max_users = Column(Integer, default=5, nullable=False)
|
|
max_storage_gb = Column(Integer, default=10, nullable=False)
|
|
max_monthly_operations = Column(Integer, default=1000, nullable=False)
|
|
|
|
# Features habilitadas (booleans)
|
|
feature_api_access = Column(Boolean, default=True)
|
|
feature_advanced_reports = Column(Boolean, default=False)
|
|
feature_integrations = Column(Boolean, default=False)
|
|
feature_dedicated_support = Column(Boolean, default=False)
|
|
|
|
# Vigencia
|
|
starts_at = Column(DateTime(timezone=True), nullable=False)
|
|
expires_at = Column(DateTime(timezone=True), nullable=False)
|
|
|
|
# Timestamps
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False)
|
|
|
|
def __repr__(self):
|
|
return f"<License(tenant_id={self.tenant_id}, plan={self.plan.value}, status={self.status.value})>"
|
|
|
|
|
|
class LicenseUsage(Base):
|
|
"""
|
|
Modelo para tracking de uso de licencia
|
|
"""
|
|
__tablename__ = "license_usage"
|
|
__table_args__ = {"schema": "a76"}
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
tenant_id = Column(Integer, ForeignKey("a76.tenants.id"), nullable=False, index=True)
|
|
|
|
# Métricas de uso
|
|
period_start = Column(DateTime(timezone=True), nullable=False)
|
|
period_end = Column(DateTime(timezone=True), nullable=False)
|
|
|
|
active_users = Column(Integer, default=0)
|
|
storage_used_gb = Column(Integer, default=0)
|
|
operations_count = Column(Integer, default=0)
|
|
api_calls_count = Column(Integer, default=0)
|
|
|
|
# Timestamps
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False)
|
|
|
|
def __repr__(self):
|
|
return f"<LicenseUsage(tenant_id={self.tenant_id}, operations={self.operations_count})>"
|