Skip to content

Commit

Permalink
Fix use of template0 and template1 with postgres.
Browse files Browse the repository at this point in the history
template1 is the default template for creating a database with Postgres.
Also, tasks should connect to 'postgres' when issuing commands like CREATE DATABASE, not template1.
  • Loading branch information
funkybob authored and kvesteri committed Apr 2, 2018
1 parent 9575576 commit d7f2905
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sqlalchemy_utils/functions/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def get_scalar_result(engine, sql):
url = copy(make_url(url))
database = url.database
if url.drivername.startswith('postgres'):
url.database = 'template1'
url.database = 'postgres'
else:
url.database = None

Expand Down Expand Up @@ -529,7 +529,7 @@ def create_database(url, encoding='utf8', template=None):
database = url.database

if url.drivername.startswith('postgres'):
url.database = 'template1'
url.database = 'postgres'
elif not url.drivername.startswith('sqlite'):
url.database = None

Expand All @@ -544,7 +544,7 @@ def create_database(url, encoding='utf8', template=None):
)

if not template:
template = 'template0'
template = 'template1'

text = "CREATE DATABASE {0} ENCODING '{1}' TEMPLATE {2}".format(
quote(engine, database),
Expand Down Expand Up @@ -591,7 +591,7 @@ def drop_database(url):
database = url.database

if url.drivername.startswith('postgres'):
url.database = 'template1'
url.database = 'postgres'
elif not url.drivername.startswith('sqlite'):
url.database = None

Expand Down

0 comments on commit d7f2905

Please sign in to comment.