1010from pydantic import BaseModel
1111
1212from config import config
13+ from config import DefaultConfig
1314from gitlab_model import GLEmojiAttributes
1415from gitlab_model import MergeRequestPayload
1516from gitlab_model import PipelinePayload
@@ -34,20 +35,21 @@ def __init__(
3435
3536
3637class DatabaseLifecycleHandler :
37- def __init__ (self , dsn : str , debug_queries : bool ):
38+ def __init__ (self , conf : DefaultConfig ):
3839 self ._pool : asyncpg .Pool | None = None
39- self .debug_queries = debug_queries
40- self .dsn = dsn
40+ self ._config = conf
4141
4242 async def connect (self ):
4343 log .debug ("creating database connection pool" )
4444 self ._pool = await asyncpg .create_pool (
45- dsn = self .dsn ,
45+ dsn = self ._config . DATABASE_URL ,
4646 server_settings = {
4747 "application_name" : "notiteams-gitlab-mr-api" ,
4848 },
4949 connection_class = NoResetConnection ,
5050 init = self .init_connection ,
51+ min_size = self ._config .DATABASE_POOL_MIN_SIZE ,
52+ max_size = self ._config .DATABASE_POOL_MAX_SIZE ,
5153 )
5254
5355 # Simple check at startup, will validate database resolution and creds
@@ -58,7 +60,7 @@ async def init_connection(self, conn: asyncpg.Connection) -> None:
5860 log .debug ("connecting to database" )
5961 await conn .set_type_codec ("jsonb" , encoder = json .dumps , decoder = json .loads , schema = "pg_catalog" )
6062
61- if self .debug_queries :
63+ if self ._config . log_queries :
6264
6365 def relog (value : asyncpg .connection .LoggedQuery ):
6466 log .debug (
@@ -296,5 +298,5 @@ async def _generic_norm_upsert(
296298 return row
297299
298300
299- database = DatabaseLifecycleHandler (config . DATABASE_URL , config . log_queries )
301+ database = DatabaseLifecycleHandler (config )
300302dbh = DBHelper (database )
0 commit comments