diff --git a/dialog_lib/db/session.py b/dialog_lib/db/session.py index 42fc9b1..4783faf 100644 --- a/dialog_lib/db/session.py +++ b/dialog_lib/db/session.py @@ -5,12 +5,15 @@ from contextlib import contextmanager -engine = sa.create_engine(os.environ.get("DATABASE_URL")) -Session = sessionmaker(bind=engine) +from functools import cache + +@cache +def get_engine(): + return sa.create_engine(os.environ.get("DATABASE_URL")) @contextmanager def session_scope(): - with Session(bind=engine) as session: + with Session(bind=get_engine()) as session: try: yield session session.commit() @@ -22,4 +25,4 @@ def session_scope(): def get_session(): with session_scope() as session: - return session \ No newline at end of file + return session diff --git a/docker-compose.yml b/docker-compose.yml index 30cc83e..9b814a1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,11 @@ -version: '3.3' +version: "3.3" services: db: image: pgvector/pgvector:pg15 restart: always volumes: - - ./etc/db-ext-vector-test.sql:/docker-entrypoint-initdb.d/init.sql - - postgres_data:/var/lib/postgresql/data/ + - ./etc/db-ext-vector-test.sql:/docker-entrypoint-initdb.d/init.sql + - postgres_data:/var/lib/postgresql/data/ environment: POSTGRES_USER: talkdai POSTGRES_PASSWORD: talkdai