summaryrefslogtreecommitdiff
path: root/django/db/migrations/executor.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-11-05 20:53:39 +0100
committerClaude Paroz <claude@2xlibre.net>2015-01-02 15:37:10 +0100
commit1aa3e09c2043c88a760e8b73fb95dc8f1ffef50e (patch)
tree54581914dbd6ec66f3099497381d29f161c702a1 /django/db/migrations/executor.py
parent2a9c4b4901d385f68a2c3f9cf98b7a776c2976f0 (diff)
downloaddjango-1aa3e09c2043c88a760e8b73fb95dc8f1ffef50e.tar.gz
Fixed #23745 -- Reused states as much as possible in migrations
Thanks Tim Graham and Markus Holtermann for the reviews.
Diffstat (limited to 'django/db/migrations/executor.py')
-rw-r--r--django/db/migrations/executor.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/django/db/migrations/executor.py b/django/db/migrations/executor.py
index 2e42e7c6d5..a7989c4107 100644
--- a/django/db/migrations/executor.py
+++ b/django/db/migrations/executor.py
@@ -98,13 +98,13 @@ class MigrationExecutor(object):
self.progress_callback("apply_start", migration, fake)
if not fake:
# Test to see if this is an already-applied initial migration
- if self.detect_soft_applied(state, migration):
+ applied, state = self.detect_soft_applied(state, migration)
+ if applied:
fake = True
else:
# Alright, do it normally
with self.connection.schema_editor() as schema_editor:
- project_state = self.loader.project_state((migration.app_label, migration.name), at_end=False)
- migration.apply(project_state, schema_editor)
+ state = migration.apply(state, schema_editor)
# For replacement migrations, record individual statuses
if migration.replaces:
for app_label, name in migration.replaces:
@@ -124,8 +124,7 @@ class MigrationExecutor(object):
self.progress_callback("unapply_start", migration, fake)
if not fake:
with self.connection.schema_editor() as schema_editor:
- project_state = self.loader.project_state((migration.app_label, migration.name), at_end=False)
- migration.unapply(project_state, schema_editor)
+ state = migration.unapply(state, schema_editor)
# For replacement migrations, record individual statuses
if migration.replaces:
for app_label, name in migration.replaces:
@@ -143,12 +142,15 @@ class MigrationExecutor(object):
tables it would create exist. This is intended only for use
on initial migrations (as it only looks for CreateModel).
"""
- project_state = self.loader.project_state((migration.app_label, migration.name), at_end=True)
- apps = project_state.apps
- found_create_migration = False
# Bail if the migration isn't the first one in its app
if [name for app, name in migration.dependencies if app == migration.app_label]:
- return False
+ return False, project_state
+ if project_state is None:
+ after_state = self.loader.project_state((migration.app_label, migration.name), at_end=True)
+ else:
+ after_state = migration.mutate_state(project_state)
+ apps = after_state.apps
+ found_create_migration = False
# Make sure all create model are done
for operation in migration.operations:
if isinstance(operation, migrations.CreateModel):
@@ -158,8 +160,8 @@ class MigrationExecutor(object):
# main app cache, as it's not a direct dependency.
model = global_apps.get_model(model._meta.swapped)
if model._meta.db_table not in self.connection.introspection.table_names(self.connection.cursor()):
- return False
+ return False, project_state
found_create_migration = True
# If we get this far and we found at least one CreateModel migration,
# the migration is considered implicitly applied.
- return found_create_migration
+ return found_create_migration, after_state