fixed the create database part of postgresql.py (#1072)

This commit is contained in:
Achintya Jai 2025-05-28 03:40:28 +05:30 committed by GitHub
parent 10c95512e6
commit 4fd743a15d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 4 deletions

View File

@ -10,7 +10,6 @@ def postgres_create_database():
when using postgres database, this is the function that is used to
create the database for the first time when you the nettacker run module.
"""
try:
engine = create_engine(
"postgresql+psycopg2://{username}:{password}@{host}:{port}/{name}".format(
@ -21,15 +20,14 @@ def postgres_create_database():
except OperationalError:
# if the database does not exist
engine = create_engine(
"postgresql+psycopg2://{username}:{password}@{host}:{port}/{name}".format(
"postgresql+psycopg2://{username}:{password}@{host}:{port}/postgres".format(
**Config.db.as_dict()
)
)
conn = engine.connect()
conn.execute("commit")
conn = conn.execution_options(isolation_level="AUTOCOMMIT")
conn.execute(text(f"CREATE DATABASE {Config.db.name}"))
conn.close()
engine = create_engine(
"postgresql+psycopg2://{username}:{password}@{host}:{port}/{name}".format(
**Config.db.as_dict()