Fix tenant register 2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# services/tenant/app/main.py
|
||||
"""
|
||||
Tenant Service FastAPI application
|
||||
Tenant Service FastAPI application - FIXED VERSION
|
||||
"""
|
||||
|
||||
import structlog
|
||||
@@ -47,11 +47,35 @@ async def startup_event():
|
||||
"""Initialize service on startup"""
|
||||
logger.info("Starting Tenant Service...")
|
||||
|
||||
try:
|
||||
# ✅ FIX: Import models to ensure they're registered with SQLAlchemy
|
||||
from app.models.tenants import Tenant, TenantMember, Subscription
|
||||
logger.info("Tenant models imported successfully")
|
||||
|
||||
# ✅ FIX: Create database tables on startup
|
||||
await database_manager.create_tables()
|
||||
logger.info("Tenant database tables created successfully")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to initialize tenant service: {e}")
|
||||
raise
|
||||
|
||||
logger.info("Tenant Service startup completed successfully")
|
||||
|
||||
@app.on_event("shutdown")
|
||||
async def shutdown_event():
|
||||
"""Cleanup on shutdown"""
|
||||
logger.info("Shutting down Tenant Service...")
|
||||
await database_manager.engine.dispose()
|
||||
|
||||
try:
|
||||
# Close database connections properly
|
||||
if hasattr(database_manager, 'engine') and database_manager.engine:
|
||||
await database_manager.engine.dispose()
|
||||
logger.info("Database connections closed")
|
||||
except Exception as e:
|
||||
logger.error(f"Error during shutdown: {e}")
|
||||
|
||||
logger.info("Tenant Service shutdown completed")
|
||||
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
|
||||
Reference in New Issue
Block a user