Skip to content

Commit

Permalink
add owner option to set ownership of newly created database to anothe…
Browse files Browse the repository at this point in the history
…r role then the user provided by settings or --user
  • Loading branch information
trbs committed Oct 28, 2013
1 parent bacbcaa commit 70108f7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion django_extensions/management/commands/reset_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class Command(BaseCommand):
make_option('-U', '--user', action='store',
dest='user', default=None,
help='Use another user for the database then defined in settings.py'),
make_option('-O', '--owner', action='store',
dest='owner', default=None,
help='Use another owner for creating the database then the user defined in settings or via --user'),
make_option('-P', '--password', action='store',
dest='password', default=None,
help='Use another password for the database then defined in settings.py'),
Expand Down Expand Up @@ -47,6 +50,7 @@ def handle(self, *args, **options):
engine = dbinfo.get('ENGINE').split('.')[-1]
user = options.get('user') or dbinfo.get('USER')
password = options.get('password') or dbinfo.get('PASSWORD')
owner = options.get('owner') or user

database_name = options.get('dbname') or dbinfo.get('NAME')
if database_name == '':
Expand Down Expand Up @@ -130,7 +134,8 @@ def handle(self, *args, **options):
logging.info("Error: %s" % str(e))

create_query = "CREATE DATABASE %s" % database_name
create_query += " WITH OWNER = %s " % user
if owner:
create_query += " WITH OWNER = %s " % owner
create_query += " ENCODING = 'UTF8'"

if engine == 'postgis':
Expand Down

0 comments on commit 70108f7

Please sign in to comment.