1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

[soc2009/multidb] Updated management commands to ensure that a database name is always available. Patch from Russell Keith-Magee.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11950 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2009-12-22 14:37:40 +00:00
parent 27c43c3acc
commit 45b4288bb6
16 changed files with 52 additions and 57 deletions

View File

@ -18,7 +18,7 @@ class Command(LabelCommand):
requires_model_validation = False requires_model_validation = False
def handle_label(self, tablename, **options): def handle_label(self, tablename, **options):
alias = options['database'] alias = options.get('database', DEFAULT_DB_ALIAS)
connection = connections[alias] connection = connections[alias]
fields = ( fields = (
# "key" is a reserved word in MySQL, so use "cache_key" instead. # "key" is a reserved word in MySQL, so use "cache_key" instead.

View File

@ -16,7 +16,7 @@ class Command(BaseCommand):
requires_model_validation = False requires_model_validation = False
def handle(self, **options): def handle(self, **options):
connection = connections[options['database']] connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
try: try:
connection.client.runshell() connection.client.runshell()
except OSError: except OSError:

View File

@ -28,7 +28,7 @@ class Command(BaseCommand):
format = options.get('format','json') format = options.get('format','json')
indent = options.get('indent',None) indent = options.get('indent',None)
using = options['database'] using = options.get('database', DEFAULT_DB_ALIAS)
connection = connections[using] connection = connections[using]
exclude = options.get('exclude',[]) exclude = options.get('exclude',[])
show_traceback = options.get('traceback', False) show_traceback = options.get('traceback', False)

View File

@ -21,26 +21,21 @@ class Command(NoArgsCommand):
help = "Executes ``sqlflush`` on the current database." help = "Executes ``sqlflush`` on the current database."
def handle_noargs(self, **options): def handle_noargs(self, **options):
if not options['database']: db = options.get('database', DEFAULT_DB_ALIAS)
dbs = connections connection = connections[db]
else:
dbs = [options['database']]
verbosity = int(options.get('verbosity', 1)) verbosity = int(options.get('verbosity', 1))
interactive = options.get('interactive') interactive = options.get('interactive')
self.style = no_style() self.style = no_style()
# Import the 'management' module within each installed app, to register
# dispatcher events.
for app_name in settings.INSTALLED_APPS: for app_name in settings.INSTALLED_APPS:
try: try:
import_module('.management', app_name) import_module('.management', app_name)
except ImportError: except ImportError:
pass pass
for db in dbs:
connection = connections[db]
# Import the 'management' module within each installed app, to register
# dispatcher events.
sql_list = sql_flush(self.style, connection, only_django=True) sql_list = sql_flush(self.style, connection, only_django=True)
if interactive: if interactive:

View File

@ -23,7 +23,7 @@ class Command(NoArgsCommand):
raise CommandError("Database inspection isn't supported for the currently selected database backend.") raise CommandError("Database inspection isn't supported for the currently selected database backend.")
def handle_inspection(self, options): def handle_inspection(self, options):
connection = connections[options['database']] connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
table2model = lambda table_name: table_name.title().replace('_', '').replace(' ', '').replace('-', '') table2model = lambda table_name: table_name.title().replace('_', '').replace(' ', '').replace('-', '')

View File

@ -36,7 +36,7 @@ class Command(BaseCommand):
) )
def handle(self, *fixture_labels, **options): def handle(self, *fixture_labels, **options):
using = options['database'] using = options.get('database', DEFAULT_DB_ALIAS)
excluded_apps = options.get('exclude', []) excluded_apps = options.get('exclude', [])
connection = connections[using] connection = connections[using]

View File

@ -20,7 +20,7 @@ class Command(AppCommand):
output_transaction = True output_transaction = True
def handle_app(self, app, **options): def handle_app(self, app, **options):
using = options['database'] using = options.get('database', DEFAULT_DB_ALIAS)
connection = connections[using] connection = connections[using]
app_name = app.__name__.split('.')[-2] app_name = app.__name__.split('.')[-2]

View File

@ -16,4 +16,4 @@ class Command(AppCommand):
output_transaction = True output_transaction = True
def handle_app(self, app, **options): def handle_app(self, app, **options):
return u'\n'.join(sql_create(app, self.style, connections[options['database']])).encode('utf-8') return u'\n'.join(sql_create(app, self.style, connections[options.get('database', DEFAULT_DB_ALIAS)])).encode('utf-8')

View File

@ -16,4 +16,4 @@ class Command(AppCommand):
output_transaction = True output_transaction = True
def handle_app(self, app, **options): def handle_app(self, app, **options):
return u'\n'.join(sql_all(app, self.style, connections[options['database']])).encode('utf-8') return u'\n'.join(sql_all(app, self.style, connections[options.get('database', DEFAULT_DB_ALIAS)])).encode('utf-8')

View File

@ -16,4 +16,4 @@ class Command(AppCommand):
output_transaction = True output_transaction = True
def handle_app(self, app, **options): def handle_app(self, app, **options):
return u'\n'.join(sql_delete(app, self.style, connections[options['database']])).encode('utf-8') return u'\n'.join(sql_delete(app, self.style, connections[options.get('database', DEFAULT_DB_ALIAS)])).encode('utf-8')

View File

@ -16,4 +16,4 @@ class Command(AppCommand):
output_transaction = True output_transaction = True
def handle_app(self, app, **options): def handle_app(self, app, **options):
return u'\n'.join(sql_custom(app, self.style, connections[options['database']])).encode('utf-8') return u'\n'.join(sql_custom(app, self.style, connections[options.get('database', DEFAULT_DB_ALIAS)])).encode('utf-8')

View File

@ -16,4 +16,4 @@ class Command(NoArgsCommand):
output_transaction = True output_transaction = True
def handle_noargs(self, **options): def handle_noargs(self, **options):
return u'\n'.join(sql_flush(self.style, connections[options['database']], only_django=True)).encode('utf-8') return u'\n'.join(sql_flush(self.style, connections[options.get('database', DEFAULT_DB_ALIAS)], only_django=True)).encode('utf-8')

View File

@ -17,4 +17,4 @@ class Command(AppCommand):
output_transaction = True output_transaction = True
def handle_app(self, app, **options): def handle_app(self, app, **options):
return u'\n'.join(sql_indexes(app, self.style, connections[options['database']])).encode('utf-8') return u'\n'.join(sql_indexes(app, self.style, connections[options.get('database', DEFAULT_DB_ALIAS)])).encode('utf-8')

View File

@ -17,4 +17,4 @@ class Command(AppCommand):
output_transaction = True output_transaction = True
def handle_app(self, app, **options): def handle_app(self, app, **options):
return u'\n'.join(sql_reset(app, self.style, connections[options['database']])).encode('utf-8') return u'\n'.join(sql_reset(app, self.style, connections[options.get('database', DEFAULT_DB_ALIAS)])).encode('utf-8')

View File

@ -16,5 +16,5 @@ class Command(AppCommand):
output_transaction = True output_transaction = True
def handle_app(self, app, **options): def handle_app(self, app, **options):
connection = connections[options['database']] connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
return u'\n'.join(connection.ops.sequence_reset_sql(self.style, models.get_models(app))).encode('utf-8') return u'\n'.join(connection.ops.sequence_reset_sql(self.style, models.get_models(app))).encode('utf-8')

View File

@ -49,7 +49,7 @@ class Command(NoArgsCommand):
if not msg.startswith('No module named') or 'management' not in msg: if not msg.startswith('No module named') or 'management' not in msg:
raise raise
db = options['database'] db = options.get('database', DEFAULT_DB_ALIAS)
connection = connections[db] connection = connections[db]
cursor = connection.cursor() cursor = connection.cursor()