Improve AI logic

This commit is contained in:
Urtzi Alfaro
2025-11-05 13:34:56 +01:00
parent 5c87fbcf48
commit 394ad3aea4
218 changed files with 30627 additions and 7658 deletions

View File

@@ -176,15 +176,25 @@ async def seed_tenants(db: AsyncSession) -> dict:
# Create demo subscriptions for all tenants (enterprise tier for full demo access)
from app.models.tenants import Subscription
# 'select' is already imported at the top of the file, so no need to import locally
for tenant_data in TENANTS_DATA:
tenant_id = tenant_data["id"]
# Check if subscription already exists
result = await db.execute(
select(Subscription).where(Subscription.tenant_id == tenant_id)
)
existing_subscription = result.scalars().first()
try:
result = await db.execute(
select(Subscription).where(Subscription.tenant_id == tenant_id)
)
existing_subscription = result.scalars().first()
except Exception as e:
# If there's a column error (like missing cancellation_effective_date),
# we need to ensure migrations are applied first
if "does not exist" in str(e):
logger.error("Database schema does not match model. Ensure migrations are applied first.")
raise
else:
raise # Re-raise if it's a different error
if not existing_subscription:
logger.info(