1010import redis .asyncio
1111import sqlalchemy as sa
1212from disnake .ext import commands
13- from sqlalchemy .ext .asyncio import AsyncSession , async_sessionmaker , create_async_engine
13+ from sqlalchemy .ext .asyncio import AsyncEngine , AsyncSession , async_sessionmaker
1414from sqlalchemy .orm import selectinload
1515
1616from monty import constants
@@ -50,7 +50,13 @@ class Monty(commands.Bot):
5050
5151 name = constants .Client .name
5252
53- def __init__ (self , redis_session : redis .asyncio .Redis , proxy : str | None = None , ** kwargs ) -> None :
53+ def __init__ (
54+ self ,
55+ redis_session : redis .asyncio .Redis ,
56+ database_engine : AsyncEngine ,
57+ proxy : str | None = None ,
58+ ** kwargs ,
59+ ) -> None :
5460 if TEST_GUILDS :
5561 kwargs ["test_guilds" ] = TEST_GUILDS
5662 log .warning ("registering as test_guilds" )
@@ -62,8 +68,8 @@ def __init__(self, redis_session: redis.asyncio.Redis, proxy: str | None = None,
6268
6369 self .create_http_session (proxy = proxy )
6470
65- self .db_engine = engine = create_async_engine ( constants . Database . postgres_bind )
66- self .db_session = async_sessionmaker (engine , expire_on_commit = False , class_ = AsyncSession )
71+ self .db_engine = database_engine
72+ self .db_session = async_sessionmaker (database_engine , expire_on_commit = False , class_ = AsyncSession )
6773
6874 self .guild_configs : dict [int , GuildConfig ] = {}
6975 self .guild_db : dict [int , Guild ] = {}
@@ -161,8 +167,6 @@ async def get_prefix(self, message: disnake.Message) -> list[str] | str | None:
161167
162168 async def _create_features (self ) -> None :
163169 """Update the database with all features defined immediately upon launch. No more lazy creation."""
164- await self .wait_until_first_connect ()
165-
166170 async with self ._feature_db_lock , self .db .begin () as session :
167171 stmt = sa .select (Feature ).options (selectinload (Feature .rollout ))
168172 result = await session .scalars (stmt )
0 commit comments