summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTim Schilling <schilling711@gmail.com>2019-03-07 18:36:55 -0600
committerTim Graham <timograham@gmail.com>2019-03-07 19:36:55 -0500
commit371ddade1e4e28827fd45e041c9410f8b4f01067 (patch)
tree351d484551f81001980e9e3fc16ee006000bb44e /django
parentacc041984fac1e79d9a1258c94479dd3ffc7f186 (diff)
Refs #30186 -- Changed MigrationRecorder.applied_migrations() to return a dict.
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/executor.py10
-rw-r--r--django/db/migrations/loader.py6
-rw-r--r--django/db/migrations/recorder.py9
3 files changed, 14 insertions, 11 deletions
diff --git a/django/db/migrations/executor.py b/django/db/migrations/executor.py
index 4aaa91ef33..7b779819e9 100644
--- a/django/db/migrations/executor.py
+++ b/django/db/migrations/executor.py
@@ -25,9 +25,9 @@ class MigrationExecutor:
"""
plan = []
if clean_start:
- applied = set()
+ applied = {}
else:
- applied = set(self.loader.applied_migrations)
+ applied = dict(self.loader.applied_migrations)
for target in targets:
# If the target is (app_label, None), that means unmigrate everything
if target[1] is None:
@@ -36,7 +36,7 @@ class MigrationExecutor:
for migration in self.loader.graph.backwards_plan(root):
if migration in applied:
plan.append((self.loader.graph.nodes[migration], True))
- applied.remove(migration)
+ applied.pop(migration)
# If the migration is already applied, do backwards mode,
# otherwise do forwards mode.
elif target in applied:
@@ -53,12 +53,12 @@ class MigrationExecutor:
for migration in self.loader.graph.backwards_plan(node):
if migration in applied:
plan.append((self.loader.graph.nodes[migration], True))
- applied.remove(migration)
+ applied.pop(migration)
else:
for migration in self.loader.graph.forwards_plan(target):
if migration not in applied:
plan.append((self.loader.graph.nodes[migration], False))
- applied.add(migration)
+ applied[migration] = self.loader.graph.nodes[migration]
return plan
def _create_project_state(self, with_applied_migrations=False):
diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py
index 54e1cefb00..8c308621d2 100644
--- a/django/db/migrations/loader.py
+++ b/django/db/migrations/loader.py
@@ -206,7 +206,7 @@ class MigrationLoader:
self.load_disk()
# Load database data
if self.connection is None:
- self.applied_migrations = set()
+ self.applied_migrations = {}
else:
recorder = MigrationRecorder(self.connection)
self.applied_migrations = recorder.applied_migrations()
@@ -232,9 +232,9 @@ class MigrationLoader:
# Ensure the replacing migration is only marked as applied if all of
# its replacement targets are.
if all(applied_statuses):
- self.applied_migrations.add(key)
+ self.applied_migrations[key] = migration
else:
- self.applied_migrations.discard(key)
+ self.applied_migrations.pop(key, None)
# A replacing migration can be used if either all or none of its
# replacement targets have been applied.
if all(applied_statuses) or (not any(applied_statuses)):
diff --git a/django/db/migrations/recorder.py b/django/db/migrations/recorder.py
index ad5435d906..c3ed4148e7 100644
--- a/django/db/migrations/recorder.py
+++ b/django/db/migrations/recorder.py
@@ -69,13 +69,16 @@ class MigrationRecorder:
raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
def applied_migrations(self):
- """Return a set of (app, name) of applied migrations."""
+ """
+ Return a dict mapping (app_name, migration_name) to Migration instances
+ for all applied migrations.
+ """
if self.has_table():
- return {tuple(x) for x in self.migration_qs.values_list('app', 'name')}
+ return {(migration.app, migration.name): migration for migration in self.migration_qs}
else:
# If the django_migrations table doesn't exist, then no migrations
# are applied.
- return set()
+ return {}
def record_applied(self, app, name):
"""Record that a migration was applied."""