def METHOD_NAME(
    previous_migrations: List[Migration],
    collected_migrations: List[Migration],
    executed_migrations: List[Migration],
    exception: Optional[Type[Exception]],
) -> None:
    for migration in previous_migrations:
        DatabaseMigration(version=migration.version, description=migration.description).save()
    assert DatabaseMigration.objects.distinct("version") == [migration.version for migration in previous_migrations]
    plan = Plan(collected_migrations=collected_migrations)
    assert plan.executed_migrations == []
    if exception is None:
        # up worked
        plan.apply()
    else:
        # up failed
        with pytest.raises(exception):
            plan.apply()
    assert plan.executed_migrations == executed_migrations
    assert DatabaseMigration.objects.distinct("version") == [
        migration.version for migration in (previous_migrations + executed_migrations)
    ]