def apply_initial_migration(self, targets: MigrationSpec) -> ProjectState: """Reverse back to the original migration.""" targets = normalize(targets) style = no_style() # start from clean database state sql.drop_models_tables(self._database, style) sql.flush_django_migrations_table(self._database, style) # prepare as broad plan as possible based on full plan self._executor.loader.build_graph() # reload full_plan = self._executor.migration_plan( self._executor.loader.graph.leaf_nodes(), clean_start=True, ) plan = truncate_plan(targets, full_plan) # apply all migrations from generated plan on clean database # (only forward, so any unexpected migration won't be applied) # to restore database state before tested migration return self._migrate(targets, plan=plan)
def test_normalize_list_of_targets(): """Ensure normalize works for list of ``MigrationTarget``.""" migration_targets = [('app1', None), ('app2', '0001_initial')] assert normalize(migration_targets) == migration_targets
def test_normalize_raw_target(): """Ensure normalize works for ``MigrationTarget``.""" assert normalize(('app', '0074_magic')) == [('app', '0074_magic')]
def apply_tested_migration(self, targets: MigrationSpec) -> ProjectState: """Apply the next migration.""" self._executor.loader.build_graph() # reload return self._migrate(normalize(targets))