Skip to content

Commit

Permalink
Use re-init for SQL echo test endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-jvessella committed Apr 15, 2024
1 parent 63eba69 commit d4149ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 3 additions & 2 deletions gamebrain/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ async def init_db(
cls,
connection_string: str = "",
drop_first=False,
echo=False
echo=False,
change_echo=False,
):
if cls.engine and not drop_first:
if cls.engine and not (drop_first or change_echo):
return
cls.engine = create_async_engine(
connection_string,
Expand Down
19 changes: 13 additions & 6 deletions gamebrain/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from .auth import admin_api_key_dependency
from .config import get_settings, SettingsModel
from .clients import topomojo
from .db import get_active_game_sessions, get_all_sessions
from .db import get_active_game_sessions, get_all_sessions, DBManager
import gamebrain.gamedata.cache as cache
from .gamedata.cache import (
GameDataCacheSnapshot,
Expand Down Expand Up @@ -215,11 +215,18 @@ async def test_change_echo_sql(state: bool) -> None:
# Dirty workaround to avoid having to re-init the DB engine
# or dig through its source to figure out how to change
# the setting.
if state:
level = logging.INFO
else:
level = logging.NOTSET
logging.getLogger("sqlalchemy.engine").setLevel(level)
# if state:
# level = logging.INFO
# else:
# level = logging.NOTSET
# logging.getLogger("sqlalchemy.engine").setLevel(level)
settings = get_settings()
await DBManager.init_db(
settings.db.connection_string,
False,
state,
True,
)


@test_router.get("/current_state")
Expand Down

0 comments on commit d4149ec

Please sign in to comment.