'Take a migration plan and return a list of collected SQL statements
that represent the best-efforts version of that plan.'

def collect_sql(self, plan):

    statements = []
    state = None
    for (migration, backwards) in plan:
        with self.connection.schema_editor(collect_sql=True, atomic=migration.atomic) as schema_editor:
            if (state is None):
                state = self.loader.project_state((migration.app_label, migration.name), at_end=False)
            if (not backwards):
                state = migration.apply(state, schema_editor, collect_sql=True)
            else:
                state = migration.unapply(state, schema_editor, collect_sql=True)
        statements.extend(schema_editor.collected_sql)
    return statements
