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 sql execution #3726

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 2 additions & 4 deletions geotrek/common/utils/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def move_models_to_schemas(app):
sql = "SELECT 1 FROM information_schema.tables WHERE table_name=%s AND table_schema!=%s"
cursor.execute(sql, [table_name, schema_name])
if cursor.fetchone():
sql = "ALTER TABLE %s SET SCHEMA %s;" % (table_name, schema_name)
cursor.execute(sql)
cursor.execute("ALTER TABLE %s SET SCHEMA %s;", [table_name, schema_name])
logger.info("Moved %s to schema %s" % (table_name, schema_name))

# For Django, search_path is set in connection options.
Expand All @@ -118,5 +117,4 @@ def move_models_to_schemas(app):
dbname = settings.DATABASES['default']['NAME']
dbuser = settings.DATABASES['default']['USER']
search_path = ', '.join(('public', ) + tuple(set(settings.DATABASE_SCHEMAS.values())))
sql = "ALTER ROLE %s IN DATABASE %s SET search_path=%s;" % (dbuser, dbname, search_path)
cursor.execute(sql)
cursor.execute("ALTER ROLE %s IN DATABASE %s SET search_path=%s;", [dbuser, dbname, search_path])
Loading