MongoMigrationHistoryService implements MigrationHistoryService { @Override public MigrationEntry getLastMigrationApplied() { final Document doc = getMigramongoCollection().find().sort(new Document("createdAt", -1)).first(); return mapMigrationEntry(doc); } 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 shouldNotReturnLastMigrationIfNoneExists() throws Exception { assertThat(migrationHistoryService.getLastMigrationApplied(), nullValue()); }
@Test public void shouldAddInitialMigrationInfo() throws Exception { addMigration(new InitialMigrationInfo("1")); assertThat(migrationHistoryService.getLastMigrationApplied(), hasProperty("fromVersion", is("1"))); }
@Test public void shouldAddInitialAndOneMigrationInfo() throws Exception { addMigration(new InitialMigrationInfo("1")); addMigration(new MigrationInfo("1", "2")); assertThat( migrationHistoryService.getLastMigrationApplied(), allOf(hasProperty("fromVersion", is("1")), hasProperty("toVersion", is("2")))); }