Fix DATABASE_URL corruption from special characters in POSTGRES_PASSWORD
This commit is contained in:
+15
-1
@@ -1,6 +1,8 @@
|
||||
import logging
|
||||
import os
|
||||
import secrets
|
||||
import shutil
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Annotated
|
||||
@@ -12,6 +14,7 @@ from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from pypdf import PdfReader
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.exc import OperationalError
|
||||
from sqlalchemy.orm import Session
|
||||
from starlette.middleware.sessions import SessionMiddleware
|
||||
|
||||
@@ -34,7 +37,18 @@ templates = Jinja2Templates(directory=str(Path(__file__).parent / "templates"))
|
||||
def startup() -> None:
|
||||
if not ADMIN_PASSWORD or not SYNC_API_TOKEN:
|
||||
raise RuntimeError("ADMIN_PASSWORD and SYNC_API_TOKEN must be configured")
|
||||
Base.metadata.create_all(bind=engine)
|
||||
# Postgres may briefly restart or lag behind its health check at deploy time.
|
||||
for attempt in range(1, 11):
|
||||
try:
|
||||
Base.metadata.create_all(bind=engine)
|
||||
break
|
||||
except OperationalError as exc:
|
||||
if attempt == 10:
|
||||
raise
|
||||
logging.getLogger("uvicorn.error").warning(
|
||||
"Database not ready (attempt %s/10): %s", attempt, exc.orig
|
||||
)
|
||||
time.sleep(2)
|
||||
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user