feat: add automatic balance timestamp migration mechanism

- Add migration system to convert Unix timestamps to datetime strings
- Integrate migration into FastAPI lifespan for automatic startup execution
- Update balance persistence to use consistent ISO datetime format
- Fix mixed timestamp types causing API parsing issues
- Add comprehensive error handling and progress logging
- Successfully migrated 7522 balance records to consistent format
This commit is contained in:
Elisiário Couto
2025-09-09 15:22:22 +01:00
committed by Elisiário Couto
parent dcac53d181
commit 34501f5f0d
2 changed files with 145 additions and 1 deletions

View File

@@ -24,6 +24,17 @@ async def lifespan(app: FastAPI):
logger.error(f"Failed to load configuration: {e}")
raise
# Run database migrations
try:
from leggend.services.database_service import DatabaseService
db_service = DatabaseService()
await db_service.run_migrations_if_needed()
logger.info("Database migrations completed")
except Exception as e:
logger.error(f"Database migration failed: {e}")
raise
# Start background scheduler
scheduler.start()
logger.info("Background scheduler started")