fix db error

This commit is contained in:
Doctor Delpy 2025-12-11 11:17:44 +03:00
parent 698d0ca3f7
commit b0055e174f
1 changed files with 16 additions and 0 deletions

View File

@ -32,6 +32,22 @@ def _init_seed_via_db() -> bytes:
engine = create_engine(DATABASE_URL, pool_pre_ping=True) engine = create_engine(DATABASE_URL, pool_pre_ping=True)
role = os.getenv("NODE_ROLE", "worker").lower() role = os.getenv("NODE_ROLE", "worker").lower()
# Best-effort: ensure service_config table exists before waiting on it.
# This complements the synchronous init in app.__main__ and protects
# against ordering issues where _secrets is imported before that init runs.
try:
from sqlalchemy.exc import SQLAlchemyError
with engine.begin() as conn:
inspector = inspect(conn)
if not inspector.has_table('service_config'):
ServiceConfigValue.__table__.create(bind=conn, checkfirst=True)
except SQLAlchemyError as exc:
make_log("HotWallet", f"Failed to ensure service_config table: {exc}", level="error")
except Exception:
# Avoid failing hard here; the fallback waiter below may still succeed
pass
def db_ready(conn) -> bool: def db_ready(conn) -> bool:
try: try:
inspector = inspect(conn) inspector = inspect(conn)