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

@@ -6,6 +6,7 @@ Handles recipe management, production planning, and inventory consumption tracki
import time
from fastapi import FastAPI, Request
from sqlalchemy import text
from fastapi.middleware.gzip import GZipMiddleware
from .core.config import settings
@@ -19,6 +20,27 @@ from .models import recipes as recipe_models
class RecipesService(StandardFastAPIService):
"""Recipes Service with standardized setup"""
expected_migration_version = "001_initial_recipes"
async def on_startup(self, app):
"""Custom startup logic including migration verification"""
await self.verify_migrations()
await super().on_startup(app)
async def verify_migrations(self):
"""Verify database schema matches the latest migrations."""
try:
async with self.database_manager.get_session() as session:
result = await session.execute(text("SELECT version_num FROM alembic_version"))
version = result.scalar()
if version != self.expected_migration_version:
self.logger.error(f"Migration version mismatch: expected {self.expected_migration_version}, got {version}")
raise RuntimeError(f"Migration version mismatch: expected {self.expected_migration_version}, got {version}")
self.logger.info(f"Migration verification successful: {version}")
except Exception as e:
self.logger.error(f"Migration verification failed: {e}")
raise
def __init__(self):
# Define expected database tables for health checks
recipes_expected_tables = [