summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-07-26 16:47:00 +0100
committerAndrew Godwin <andrew@aeracode.org>2013-07-26 16:47:00 +0100
commit52643a69e3fac42c14143f3ca71ec9f5b7e64296 (patch)
tree2de51f15580197dc3b0b0937cd6da18252658d6a
parent3f7113f1d976a9bd668afd8114269e8c594dd842 (diff)
Add --fake option to migrate
-rw-r--r--django/core/management/commands/migrate.py6
-rw-r--r--django/db/migrations/executor.py24
2 files changed, 17 insertions, 13 deletions
diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py
index 882ebde073..73d453cf99 100644
--- a/django/core/management/commands/migrate.py
+++ b/django/core/management/commands/migrate.py
@@ -24,6 +24,8 @@ class Command(BaseCommand):
make_option('--database', action='store', dest='database',
default=DEFAULT_DB_ALIAS, help='Nominates a database to synchronize. '
'Defaults to the "default" database.'),
+ make_option('--fake', action='store_true', dest='fake', default=False,
+ help='Mark migrations as run without actually running them'),
)
help = "Updates database schema. Manages both apps with migrations and those without."
@@ -109,7 +111,7 @@ class Command(BaseCommand):
if self.verbosity >= 1:
self.stdout.write(" No migrations needed.")
else:
- executor.migrate(targets, plan)
+ executor.migrate(targets, plan, fake=options.get("fake", False))
def migration_progress_callback(self, action, migration):
if self.verbosity >= 1:
@@ -181,7 +183,7 @@ class Command(BaseCommand):
for statement in sql:
cursor.execute(statement)
tables.append(connection.introspection.table_name_converter(model._meta.db_table))
-
+
# We force a commit here, as that was the previous behaviour.
# If you can prove we don't need this, remove it.
transaction.set_dirty(using=connection.alias)
diff --git a/django/db/migrations/executor.py b/django/db/migrations/executor.py
index 46bbfc0ef2..9d99c90c11 100644
--- a/django/db/migrations/executor.py
+++ b/django/db/migrations/executor.py
@@ -44,7 +44,7 @@ class MigrationExecutor(object):
applied.add(migration)
return plan
- def migrate(self, targets, plan=None):
+ def migrate(self, targets, plan=None, fake=False):
"""
Migrates the database up to the given targets.
"""
@@ -52,32 +52,34 @@ class MigrationExecutor(object):
plan = self.migration_plan(targets)
for migration, backwards in plan:
if not backwards:
- self.apply_migration(migration)
+ self.apply_migration(migration, fake=fake)
else:
- self.unapply_migration(migration)
+ self.unapply_migration(migration, fake=fake)
- def apply_migration(self, migration):
+ def apply_migration(self, migration, fake=False):
"""
Runs a migration forwards.
"""
if self.progress_callback:
self.progress_callback("apply_start", migration)
- with self.connection.schema_editor() as schema_editor:
- project_state = self.loader.graph.project_state((migration.app_label, migration.name), at_end=False)
- migration.apply(project_state, schema_editor)
+ if not fake:
+ with self.connection.schema_editor() as schema_editor:
+ project_state = self.loader.graph.project_state((migration.app_label, migration.name), at_end=False)
+ migration.apply(project_state, schema_editor)
self.recorder.record_applied(migration.app_label, migration.name)
if self.progress_callback:
self.progress_callback("apply_success", migration)
- def unapply_migration(self, migration):
+ def unapply_migration(self, migration, fake=False):
"""
Runs a migration backwards.
"""
if self.progress_callback:
self.progress_callback("unapply_start", migration)
- with self.connection.schema_editor() as schema_editor:
- project_state = self.loader.graph.project_state((migration.app_label, migration.name), at_end=False)
- migration.unapply(project_state, schema_editor)
+ if not fake:
+ with self.connection.schema_editor() as schema_editor:
+ project_state = self.loader.graph.project_state((migration.app_label, migration.name), at_end=False)
+ migration.unapply(project_state, schema_editor)
self.recorder.record_unapplied(migration.app_label, migration.name)
if self.progress_callback:
self.progress_callback("unapply_success", migration)