Add migration services

This commit is contained in:
Urtzi Alfaro
2025-09-30 08:12:45 +02:00
parent d1c83dce74
commit ec6bcb4c7d
139 changed files with 6363 additions and 163 deletions

View File

@@ -200,10 +200,15 @@ class BaseFastAPIService:
pass
async def _initialize_database(self):
"""Initialize database connection"""
"""Initialize database connection and tables"""
try:
# Test connection
if await self.database_manager.test_connection():
self.logger.info("Database connection established")
# Handle automatic table initialization
await self._handle_database_tables()
self.logger.info("Database initialized successfully")
else:
raise Exception("Database connection test failed")
@@ -211,6 +216,29 @@ class BaseFastAPIService:
self.logger.error("Database initialization failed", error=str(e))
raise
async def _handle_database_tables(self):
"""Handle automatic table creation and migration management"""
try:
# Import the init manager here to avoid circular imports
from shared.database.init_manager import initialize_service_database
# Check if we're in force recreate mode (development)
force_recreate = os.getenv("DB_FORCE_RECREATE", "false").lower() == "true"
# Initialize database with automatic table creation
result = await initialize_service_database(
database_manager=self.database_manager,
service_name=self.service_name.replace("-service", "").replace("_", ""),
force_recreate=force_recreate
)
self.logger.info("Database table initialization completed", result=result)
except Exception as e:
self.logger.error("Database table initialization failed", error=str(e))
# Don't raise here - let the service start even if table init fails
# This allows for manual intervention if needed
async def _cleanup_database(self):
"""Cleanup database connections"""
try: