Add support to the convertdb command to operate on specified apps too.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-09-21 00:09:58 -04:00
parent 06288e3d6d
commit 9e4ad9a64f
2 changed files with 15 additions and 7 deletions

View File

@@ -4,6 +4,7 @@
* Don't use a hardcoded database alias for the destination of the database conversion.
* Improve natural key support in the UserOptions model.
* Update from Django 1.11.11 to 1.11.16
* Add support to the convertdb command to operate on specified apps too.
3.1.1 (2018-09-18)
==================

View File

@@ -22,6 +22,13 @@ class Command(management.BaseCommand):
help = 'Convert from a database backend to another one.'
def add_arguments(self, parser):
parser.add_argument(
'args', metavar='app_label[.ModelName]', nargs='*',
help=_(
'Restricts dumped data to the specified app_label or '
'app_label.ModelName.'
)
)
parser.add_argument(
'--from', action='store', default='default', dest='from',
help=_(
@@ -44,7 +51,7 @@ class Command(management.BaseCommand):
),
)
def handle(self, *args, **options):
def handle(self, *app_labels, **options):
# Create the media/convertdb folder
convertdb_folder_path = force_text(
Path(
@@ -67,10 +74,10 @@ class Command(management.BaseCommand):
management.call_command('purgeperiodictasks')
management.call_command(
'dumpdata', all=True, database=options['from'],
natural_primary=True, natural_foreign=True,
output=convertdb_file_path, interactive=False,
format='json'
'dumpdata', *app_labels, all=True,
database=options['from'], natural_primary=True,
natural_foreign=True, output=convertdb_file_path,
interactive=False, format='json'
)
if DocumentType.objects.using(options['to']).count() and not options['force']:
@@ -78,11 +85,11 @@ class Command(management.BaseCommand):
raise CommandError(
'There is existing data in the database that will be '
'used for the import. If you proceed with the conversion '
'you might lose data. Please check you settings.'
'you might lose data. Please check your settings.'
)
management.call_command(
'loaddata', convertdb_file_path, database=options['to'],
interactive=False
interactive=False, verbosity=3
)
fs_cleanup(convertdb_file_path)