Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve check for createdb privileges during setup_db re: #4941 #4997

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions arches/management/commands/setup_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ def get_connection(self):
"re-run this same command.")
exit()

cursor = conn.cursor()
cursor.execute("SELECT rolcreatedb FROM pg_roles WHERE rolname = '{}'".format(username))
cancreate = cursor.fetchone()[0]

# autocommit false
conn.set_isolation_level(0)
return conn
return {"connection": conn, "can_create_db": cancreate}

def reset_db(self, cursor):

Expand Down Expand Up @@ -160,14 +164,12 @@ def setup_db(self):
WARNING: This will destroy data
"""

conn = self.get_connection()
cursor = conn.cursor()
conninfo = self.get_connection()
conn = conninfo['connection']
can_create_db = conninfo['can_create_db']

# figure out if this is a superuser or not
cursor.execute("SELECT current_setting('is_superuser')")
superuser = True if cursor.fetchone()[0] == "on" else False

if superuser:
cursor = conn.cursor()
if can_create_db is True:
self.drop_and_recreate_db(cursor)
else:
self.reset_db(cursor)
Expand Down