24 lines
668 B
Python
24 lines
668 B
Python
from fastapi import FastAPI, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy import text
|
|
from app.database import get_db, engine
|
|
from app import models
|
|
|
|
# Create all tables
|
|
models.Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(title="Card Game Backend")
|
|
|
|
@app.get("/health")
|
|
def health_check():
|
|
return {"status": "ok"}
|
|
|
|
@app.get("/db-check")
|
|
def db_check(db: Session = Depends(get_db)):
|
|
try:
|
|
# Execute simple query to check connection
|
|
db.execute(text("SELECT 1"))
|
|
return {"db": "ok"}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"Database connection failed: {str(e)}")
|