@Override
    public void upgrade() {
        if (hasBeenRunSuccessfully()) {
            LOG.debug("Migration already completed.");
            return;
        }

        final Set<String> dashboardIdToViewId = new HashSet<>();
        final Consumer<String> recordMigratedDashboardIds = dashboardIdToViewId::add;
        final Map<String, Set<String>> widgetIdMigrationMapping = new HashMap<>();
        final Consumer<Map<String, Set<String>>> recordMigratedWidgetIds = widgetIdMigrationMapping::putAll;

        final Map<View, Search> newViews = this.dashboardsService.streamAll()
                .sorted(Comparator.comparing(Dashboard::id))
                .map(dashboard -> migrateDashboard(dashboard, recordMigratedDashboardIds, recordMigratedWidgetIds))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

        writeViews(newViews);

        final MigrationCompleted migrationCompleted = MigrationCompleted.create(dashboardIdToViewId, widgetIdMigrationMapping);

        writeMigrationCompleted(migrationCompleted);
    }
@Test
    public void runsIfNoDashboardsArePresent() {
        this.migration.upgrade();
    }