示例#1
0
    def __init__(self, using='default', loader=None, executor=None):
        connection = connections[using]
        self._loader = loader or django_migration_loader.MigrationLoader(
            connection, ignore_no_migrations=True
        )
        self._graph = self._loader.graph
        self._executor = django_migration_executor.MigrationExecutor(connection)
        self._docs = MigrationDocs()

        self._migrations = {
            str(node): Migration(
                node,
                executor=self._executor,
                loader=self._loader,
                docs=self._docs,
            )
            for node in self._graph.nodes.values()
        }

        # Construct a plan of migrations. Set the ``data`` as the plan so
        # that this datastructure is a list
        targets = self._graph.leaf_nodes()
        self.data = []
        seen = set()
        for target in targets:
            for migration in self._graph.forwards_plan(target):
                if migration not in seen:  # pragma: no branch
                    # We don't cover the "else" branch of this statement since
                    # our test models dont have complex enough migrations
                    self.data.append(self._migrations[str(self._graph.nodes[migration])])
                    seen.add(migration)
示例#2
0
def initial_django_migration(database):
    """ Check if we ever executed an initial django migration. """
    from django.db.migrations import loader  # pylint: disable=E0611
    loader = loader.MigrationLoader(django.db.connections[database])
    return len(loader.applied_migrations) == 0