Improve AI logic
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user