feat: Add database init on startup and documentation

- Add lifespan handler to main.py for automatic DB table creation
- Expand .env.example with detailed variable documentation
- Add AUDIT_REPORT.md with comprehensive product/technical review
- Add STRATEGY_SCHEMA.md as single source of truth for strategy config
- Remove redundant init_db.py script (DB init now handled by app startup)
This commit is contained in:
shokollm
2026-04-09 04:49:11 +00:00
parent 2561759b78
commit 0a2e347fdb
4 changed files with 879 additions and 1 deletions

View File

@@ -1,14 +1,35 @@
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from slowapi import Limiter
from slowapi.util import get_remote_address
from .api import auth, bots, backtest, simulate, config, ave
from .core.limiter import limiter
from .core.database import engine, Base
logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Initialize database on startup."""
# Import all models to ensure they're registered
from .db.models import User, Bot, BotConversation, Backtest, Simulation, Signal
# Create tables if they don't exist
Base.metadata.create_all(bind=engine)
logger.info("Database initialized successfully")
yield
# Cleanup on shutdown if needed
app = FastAPI(
title="Randebu Trading Bot API",
description="AI-powered trading bot platform API",
version="0.1.0",
lifespan=lifespan,
)
app.state.limiter = limiter