Last active
February 7, 2017 11:19
-
-
Save siegy22/de62a4528381da6498cb4bf191c1322a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from django.conf import settings | |
from django.core.management.base import BaseCommand, CommandError | |
class Command(BaseCommand): | |
help = "Drops your database using psql command" | |
def add_arguments(self, parser): | |
parser.add_argument( | |
'-R', '--router', action='store', dest='router', default='default', | |
help='Use this router-database other then defined in settings.py') | |
def handle(self, *args, **options): | |
router = options.get('router') | |
dbinfo = settings.DATABASES.get(router) | |
if dbinfo is None: | |
raise CommandError("Unknown database router %s" % router) | |
dbname = dbinfo.get('NAME') | |
drop_command = "DROP DATABASE {0};".format(dbname) | |
os.system('psql postgres -q -c "{0}"'.format(drop_command)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment