diff options
| author | Sebastian Spiegel <sbast@users.noreply.github.com> | 2016-11-06 13:52:06 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-01-06 19:50:31 -0500 |
| commit | 8b734d2f990063df2988143dfb5f4449b60b9ca3 (patch) | |
| tree | c35e0418b8e3e2f58cc514d621f4e2c57a5665d8 /django | |
| parent | d976760260c2d8371c1535a7bdeba9a2e0568a34 (diff) | |
Fixed #27432 -- Made app_label arguments limit showmigrations --plan output.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/management/commands/showmigrations.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/django/core/management/commands/showmigrations.py b/django/core/management/commands/showmigrations.py index 767aca139d..890839b150 100644 --- a/django/core/management/commands/showmigrations.py +++ b/django/core/management/commands/showmigrations.py @@ -43,10 +43,18 @@ class Command(BaseCommand): connection = connections[db] if options['format'] == "plan": - return self.show_plan(connection) + return self.show_plan(connection, options['app_label']) else: return self.show_list(connection, options['app_label']) + def _validate_app_names(self, loader, app_names): + invalid_apps = [] + for app_name in app_names: + if app_name not in loader.migrated_apps: + invalid_apps.append(app_name) + if invalid_apps: + raise CommandError('No migrations present for: %s' % (', '.join(sorted(invalid_apps)))) + def show_list(self, connection, app_names=None): """ Shows a list of all migrations on the system, or only those of @@ -57,12 +65,7 @@ class Command(BaseCommand): graph = loader.graph # If we were passed a list of apps, validate it if app_names: - invalid_apps = [] - for app_name in app_names: - if app_name not in loader.migrated_apps: - invalid_apps.append(app_name) - if invalid_apps: - raise CommandError("No migrations present for: %s" % (", ".join(invalid_apps))) + self._validate_app_names(loader, app_names) # Otherwise, show all apps in alphabetic order else: app_names = sorted(loader.migrated_apps) @@ -88,14 +91,19 @@ class Command(BaseCommand): if not shown: self.stdout.write(" (no migrations)", self.style.ERROR) - def show_plan(self, connection): + def show_plan(self, connection, app_names=None): """ - Shows all known migrations in the order they will be applied + Shows all known migrations (or only those of the specified app_names) + in the order they will be applied. """ # Load migrations from disk/DB loader = MigrationLoader(connection) graph = loader.graph - targets = graph.leaf_nodes() + if app_names: + self._validate_app_names(loader, app_names) + targets = [key for key in graph.leaf_nodes() if key[0] in app_names] + else: + targets = graph.leaf_nodes() plan = [] seen = set() |
