From a555c2f1b2de7d7e76d0be3e28e5a002dfbb8d4b Mon Sep 17 00:00:00 2001 From: Francois-Werbrouck <122839953+Francois-Werbrouck@users.noreply.github.com> Date: Thu, 14 Mar 2024 13:40:54 +0000 Subject: [PATCH] Fixes #81: CHANGED VARIABLES --- .env.template | 4 ++-- ailab/db/__init__.py | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.env.template b/.env.template index 45ed56e..ef76403 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,4 @@ -LOUIS_DSN= +AILAB_DSN= PGBASE= PGUSER= USER= @@ -9,6 +9,6 @@ PGDATA= OPENAI_API_KEY= OPENAI_ENDPOINT= OPENAI_API_ENGINE= -LOUIS_SCHEMA= +AILAB_SCHEMA= DB_SERVER_CONTAINER_NAME= FINESSE_WEIGHTS= diff --git a/ailab/db/__init__.py b/ailab/db/__init__.py index bc0c18e..9aa508f 100644 --- a/ailab/db/__init__.py +++ b/ailab/db/__init__.py @@ -23,22 +23,22 @@ class DBMissingEnvironmentVariable(DBError): def raise_error(message): raise DBMissingEnvironmentVariable(message) -LOUIS_DSN = os.environ.get("LOUIS_DSN") -if LOUIS_DSN is None: +AILAB_DSN = os.environ.get("AILAB_DSN") +if AILAB_DSN is None: raise ValueError("LOUIS_DSN is not set") -LOUIS_SCHEMA = os.environ.get("LOUIS_SCHEMA") -if LOUIS_SCHEMA is None: - raise ValueError("LOUIS_SCHEMA is not set") +AILAB_SCHEMA = os.environ.get("AILAB_SCHEMA") +if AILAB_SCHEMA is None: + raise ValueError("AILAB_SCHEMA is not set") def connect_db(): """Connect to the postgresql database and return the connection.""" - logger.info(f"Connecting to {LOUIS_DSN}") + logger.info(f"Connecting to {AILAB_DSN}") connection = psycopg.connect( - conninfo=LOUIS_DSN, + conninfo=AILAB_DSN, row_factory=dict_row, autocommit=False, - options=f"-c search_path={LOUIS_SCHEMA},public") + options=f"-c search_path={AILAB_SCHEMA},public") assert connection.info.encoding == 'utf-8', ( 'Encoding is not UTF8: ' + connection.info.encoding) # psycopg.extras.register_uuid() @@ -49,10 +49,10 @@ def cursor(connection): """Return a cursor for the given connection.""" return connection.cursor() -def create_postgresql_url(dbname, tablename, entity_id, parameters=None): +def create_postgresql_url(dbname, tablename, entity_id, parameters=None,schema=AILAB_SCHEMA): if parameters is None: - return f'postgresql://{dbname}/{LOUIS_SCHEMA}/{tablename}/{entity_id}' - return f'postgresql://{dbname}/{LOUIS_SCHEMA}/{tablename}/{entity_id}?{urllib.parse.urlencode(parameters)}' + return f'postgresql://{dbname}/{schema}/{tablename}/{entity_id}' + return f'postgresql://{dbname}/{schema}/{tablename}/{entity_id}?{urllib.parse.urlencode(parameters)}' def parse_postgresql_url(url):