From 058e5c9bc9ee6566fdd3ec3229b876dfc24852d3 Mon Sep 17 00:00:00 2001 From: ori Date: Wed, 30 Oct 2024 07:58:25 +0200 Subject: [PATCH] add sqlalchemy application name --- open_bus_stride_db/db.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/open_bus_stride_db/db.py b/open_bus_stride_db/db.py index 7bfd188..53276f5 100644 --- a/open_bus_stride_db/db.py +++ b/open_bus_stride_db/db.py @@ -6,10 +6,17 @@ from sqlalchemy.orm import sessionmaker, Session +SQLALCHEMY_APPLICATION_NAME = os.getenv("SQLALCHEMY_APPLICATION_NAME", "db") +SQLALCHEMY_APPLICATION_VERSION = os.getenv("SQLALCHEMY_APPLICATION_VERSION", "-") + + engine = create_engine( os.environ.get('SQLALCHEMY_URL', 'postgresql://postgres:123456@localhost'), future=True, - connect_args={"options": "-c timezone=utc"}, + connect_args={ + "options": "-c timezone=utc", + "application_name": f'{SQLALCHEMY_APPLICATION_NAME} {SQLALCHEMY_APPLICATION_VERSION}'[:64], + }, echo=bool(os.environ.get('SQLALCHEMY_ECHO')), pool_size=int(os.environ.get('SQLALCHEMY_POOL_SIZE', 10)), max_overflow=int(os.environ.get('SQLALCHEMY_MAX_OVERFLOW', 20)),