mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
Refs #31318 -- Optimized sqlmigrate by using MigrationLoader.
Only loader from MigrationExecutor was used.
This commit is contained in:
parent
71c1b7fb34
commit
271e108b29
@ -1,8 +1,7 @@
|
|||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.db import DEFAULT_DB_ALIAS, connections
|
from django.db import DEFAULT_DB_ALIAS, connections
|
||||||
from django.db.migrations.executor import MigrationExecutor
|
from django.db.migrations.loader import AmbiguityError, MigrationLoader
|
||||||
from django.db.migrations.loader import AmbiguityError
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@ -33,8 +32,8 @@ class Command(BaseCommand):
|
|||||||
# Get the database we're operating from
|
# Get the database we're operating from
|
||||||
connection = connections[options['database']]
|
connection = connections[options['database']]
|
||||||
|
|
||||||
# Load up an executor to get all the migration data
|
# Load up an loader to get all the migration data
|
||||||
executor = MigrationExecutor(connection)
|
loader = MigrationLoader(connection)
|
||||||
|
|
||||||
# Resolve command-line arguments into a migration
|
# Resolve command-line arguments into a migration
|
||||||
app_label, migration_name = options['app_label'], options['migration_name']
|
app_label, migration_name = options['app_label'], options['migration_name']
|
||||||
@ -43,10 +42,10 @@ class Command(BaseCommand):
|
|||||||
apps.get_app_config(app_label)
|
apps.get_app_config(app_label)
|
||||||
except LookupError as err:
|
except LookupError as err:
|
||||||
raise CommandError(str(err))
|
raise CommandError(str(err))
|
||||||
if app_label not in executor.loader.migrated_apps:
|
if app_label not in loader.migrated_apps:
|
||||||
raise CommandError("App '%s' does not have migrations" % app_label)
|
raise CommandError("App '%s' does not have migrations" % app_label)
|
||||||
try:
|
try:
|
||||||
migration = executor.loader.get_migration_by_prefix(app_label, migration_name)
|
migration = loader.get_migration_by_prefix(app_label, migration_name)
|
||||||
except AmbiguityError:
|
except AmbiguityError:
|
||||||
raise CommandError("More than one migration matches '%s' in app '%s'. Please be more specific." % (
|
raise CommandError("More than one migration matches '%s' in app '%s'. Please be more specific." % (
|
||||||
migration_name, app_label))
|
migration_name, app_label))
|
||||||
@ -61,8 +60,8 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
# Make a plan that represents just the requested migrations and show SQL
|
# Make a plan that represents just the requested migrations and show SQL
|
||||||
# for it
|
# for it
|
||||||
plan = [(executor.loader.graph.nodes[target], options['backwards'])]
|
plan = [(loader.graph.nodes[target], options['backwards'])]
|
||||||
sql_statements = executor.loader.collect_sql(plan)
|
sql_statements = loader.collect_sql(plan)
|
||||||
if not sql_statements and options['verbosity'] >= 1:
|
if not sql_statements and options['verbosity'] >= 1:
|
||||||
self.stderr.write('No operations found.')
|
self.stderr.write('No operations found.')
|
||||||
return '\n'.join(sql_statements)
|
return '\n'.join(sql_statements)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user