You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
orquestrador/app/main.py

44 lines
1.4 KiB
Python

from fastapi import FastAPI
from app.api.routes import router
from app.api.tool_routes import router as tool_router
from app.core.settings import settings
from app.db.database import Base, engine
from app.db.mock_database import MockBase, mock_engine
from app.db.models import Tool
from app.db.mock_models import Customer, Order, ReviewSchedule, Vehicle
app = FastAPI(title="AI Orquestrador")
app.include_router(router)
app.include_router(tool_router)
@app.on_event("startup")
async def startup_event():
"""
Inicializa o banco de dados e executa seeds automaticamente.
"""
print("[Auto-Seed] Iniciando configuracao do banco...")
# Tools (MySQL) e mock (MySQL) sobem de forma independente.
try:
Base.metadata.create_all(bind=engine)
if settings.auto_seed_tools:
from app.db.tool_seed import seed_tools
seed_tools()
print("[Auto-Seed] MySQL de tools inicializado.")
except Exception as e:
print(f"[Auto-Seed] Aviso: falha ao inicializar MySQL (tools): {e}")
try:
MockBase.metadata.create_all(bind=mock_engine)
if settings.auto_seed_mock and settings.mock_seed_enabled:
from app.db.mock_seed import seed_mock_data
seed_mock_data()
print("[Auto-Seed] MySQL de mock inicializado.")
except Exception as e:
print(f"[Auto-Seed] Aviso: falha ao inicializar MySQL (mock): {e}")
print("[Auto-Seed] Startup finalizado.")