MongoMigrationHistoryService implements MigrationHistoryService { @Override public MigrationEntry addRunToMigrationEntry(MigrationEntry migEntry, MigrationRun migRun) { final Document migEntryDoc = findMigrationDoc(migEntry.getFromVersion(), migEntry.getToVersion()); if (migEntryDoc == null) { return null; } final Document migRunDoc = mapMigRunToDoc(migRun); @SuppressWarnings("unchecked") List<Document> reRunsList = migEntryDoc.get("reruns", List.class); if (reRunsList == null) { reRunsList = new ArrayList<Document>(); } reRunsList.add(migRunDoc); migEntryDoc.put("reruns", reRunsList); replaceMigrationEntry(migEntry, migEntryDoc); return mapMigrationEntry(migEntryDoc); } MongoMigrationHistoryService(MongoDatabase database); @Override MigrationEntry insertMigrationStatusInProgress(MigrationInfo migrationInfo); @Override MigrationEntry insertMigrationStatusSkipped(MigrationInfo migrationInfo); @Override MigrationEntry setMigrationStatusToFailed(MigrationEntry migrationEntry, Exception e); @Override MigrationEntry setMigrationStatusToFinished(MigrationEntry migrationEntry); @Override MigrationEntry setMigrationStatusToManuallyRepaired(MigrationEntry migrationEntry); @Override MigrationEntry getLastMigrationApplied(); @Override Iterable<MigrationEntry> getAllMigrationsApplied(); @Override MigrationEntry findMigration(String fromVersion, String toVersion); @Override Iterable<MigrationEntry> findMigrations(String fromVersion); @Override MigrationEntry addRunToMigrationEntry(MigrationEntry migEntry, MigrationRun migRun); static final String MIGRAMONGO_COLLECTION; }
@Test public void shouldNotAddRerunToMigEntryIfEntryDoesNotExist() throws Exception { final MigrationEntry migEntry = new MigrationEntry(); migEntry.setFromVersion("1"); migEntry.setToVersion("2"); final MigrationRun migRun = new MigrationRun().complete(MigrationStatus.OK, "it's ok"); final MigrationEntry migEntryWithRuns = migrationHistoryService.addRunToMigrationEntry(migEntry, migRun); assertThat(migEntryWithRuns, nullValue()); }