feat: Add PostgreSQL database infrastructure
- Add SQLAlchemy models for User, Translation, ApiKey, UsageLog, PaymentHistory - Add database connection management with PostgreSQL/SQLite support - Add repository layer for CRUD operations - Add Alembic migration setup with initial migration - Update auth_service to automatically use database when DATABASE_URL is set - Update docker-compose.yml with PostgreSQL service and Redis (non-optional) - Add database migration script (scripts/migrate_to_db.py) - Update .env.example with database configuration
This commit is contained in:
12
main.py
12
main.py
@@ -204,6 +204,18 @@ async def lifespan(app: FastAPI):
|
||||
# Startup
|
||||
logger.info("Starting Document Translation API...")
|
||||
config.ensure_directories()
|
||||
|
||||
# Initialize database
|
||||
try:
|
||||
from database.connection import init_db, check_db_connection
|
||||
init_db()
|
||||
if check_db_connection():
|
||||
logger.info("✅ Database connection verified")
|
||||
else:
|
||||
logger.warning("⚠️ Database connection check failed")
|
||||
except Exception as e:
|
||||
logger.warning(f"⚠️ Database initialization skipped: {e}")
|
||||
|
||||
await cleanup_manager.start()
|
||||
logger.info("API ready to accept requests")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user