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

        final Map<String, String> savedSearchToViewsMap = new HashMap<>();

        final Map<View, Search> newViews = this.savedSearchService.streamAll()
                .map(savedSearch -> {
                    final Map.Entry<View, Search> newView = migrateSavedSearch(savedSearch);
                    savedSearchToViewsMap.put(savedSearch.id(), newView.getKey().id());
                    return newView;
                })
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

        newViews.forEach((view, search) -> {
            viewService.save(view);
            searchService.save(search);
        });

        final MigrationCompleted migrationCompleted = MigrationCompleted.create(savedSearchToViewsMap);
        writeMigrationCompleted(migrationCompleted);
    }
@Test
    @MongoDBFixtures("sample_saved_search_with_stream.json")
    public void migrateSavedSearchWithStreamId() throws Exception {
        this.migration.upgrade();

        final MigrationCompleted migrationCompleted = captureMigrationCompleted();
        assertThat(migrationCompleted.savedSearchIds())
                .containsExactly(new AbstractMap.SimpleEntry<>("5de660b7b2d44b5813c1d7f6", "000000020000000000000000"));

        assertViewServiceCreatedViews(1, resourceFile("sample_saved_search_with_stream-expected_views.json"));
        assertSearchServiceCreated(1, resourceFile("sample_saved_search_with_stream-expected_searches.json"));
    }