summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2020-03-08 22:48:00 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-03-09 08:23:56 +0100
commit71c1b7fb34109e6270841eb5d2dcd60f8a22453b (patch)
treee2895fa6d552c9ed708fcb6196e891fe83e84c14
parentb88ad1d356844da10035af6e09603afdaf84a169 (diff)
Refs #31318 -- Moved MigrationExecutor.collect_sql() to MigrationLoader.
collect_sql() is used only in sqlmigrate.
-rw-r--r--django/core/management/commands/sqlmigrate.py2
-rw-r--r--django/db/migrations/executor.py18
-rw-r--r--django/db/migrations/loader.py18
3 files changed, 19 insertions, 19 deletions
diff --git a/django/core/management/commands/sqlmigrate.py b/django/core/management/commands/sqlmigrate.py
index b75e0a7438..d05e615c89 100644
--- a/django/core/management/commands/sqlmigrate.py
+++ b/django/core/management/commands/sqlmigrate.py
@@ -62,7 +62,7 @@ class Command(BaseCommand):
# Make a plan that represents just the requested migrations and show SQL
# for it
plan = [(executor.loader.graph.nodes[target], options['backwards'])]
- sql_statements = executor.collect_sql(plan)
+ sql_statements = executor.loader.collect_sql(plan)
if not sql_statements and options['verbosity'] >= 1:
self.stderr.write('No operations found.')
return '\n'.join(sql_statements)
diff --git a/django/db/migrations/executor.py b/django/db/migrations/executor.py
index 2765ac28bd..83d624e08a 100644
--- a/django/db/migrations/executor.py
+++ b/django/db/migrations/executor.py
@@ -210,24 +210,6 @@ class MigrationExecutor:
return state
- def collect_sql(self, plan):
- """
- Take a migration plan and return a list of collected SQL statements
- that represent the best-efforts version of that plan.
- """
- statements = []
- state = None
- for migration, backwards in plan:
- with self.connection.schema_editor(collect_sql=True, atomic=migration.atomic) as schema_editor:
- if state is None:
- state = self.loader.project_state((migration.app_label, migration.name), at_end=False)
- if not backwards:
- state = migration.apply(state, schema_editor, collect_sql=True)
- else:
- state = migration.unapply(state, schema_editor, collect_sql=True)
- statements.extend(schema_editor.collected_sql)
- return statements
-
def apply_migration(self, state, migration, fake=False, fake_initial=False):
"""Run a migration forwards."""
migration_recorded = False
diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py
index 09a58d1e24..d41f6d3606 100644
--- a/django/db/migrations/loader.py
+++ b/django/db/migrations/loader.py
@@ -320,3 +320,21 @@ class MigrationLoader:
See graph.make_state() for the meaning of "nodes" and "at_end".
"""
return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self.unmigrated_apps))
+
+ def collect_sql(self, plan):
+ """
+ Take a migration plan and return a list of collected SQL statements
+ that represent the best-efforts version of that plan.
+ """
+ statements = []
+ state = None
+ for migration, backwards in plan:
+ with self.connection.schema_editor(collect_sql=True, atomic=migration.atomic) as schema_editor:
+ if state is None:
+ state = self.project_state((migration.app_label, migration.name), at_end=False)
+ if not backwards:
+ state = migration.apply(state, schema_editor, collect_sql=True)
+ else:
+ state = migration.unapply(state, schema_editor, collect_sql=True)
+ statements.extend(schema_editor.collected_sql)
+ return statements