@Test public void shouldExecuteMigrationScriptMarkedWithIncludedInInitialTrueIfItsNotAnInitialMigration() throws Exception { mockLastMigrationApplied("0", "1"); final List<MongoMigrationScript> migrationScripts = Arrays .asList(mockMongoScript("1", "2"), mockMongoScript("2", "3"), mockMongoScript("3", "4")); when(lookupService.findMongoScripts()).thenReturn(migrationScripts); final MigraMongoStatus status = migraMongo.migrate(); assertThat(status.status, is(MigrationStatus.OK)); assertThat(status.migrationsApplied, hasSize(migrationScripts.size())); for (MongoMigrationScript migrationScript : migrationScripts) { verify(migrationScript).migrate(mongoDatabase); } }
public MigraMongoStatus migrate() { final boolean lockAcquired = lockService.acquireLock(); if ( !lockAcquired) { return MigraMongoStatus.lockNotAcquired(); } try { final List<MongoMigrationScript> migrationScriptsToApply = findMigrationScriptsToApply(); return migrate(migrationScriptsToApply); } catch (MongoMigrationException e) { logger.error("Migration Exception caught while migrating", e); return e.getStatus(); } catch (Exception e) { logger.error("Unknown Exception caught while migrating", e); return MigraMongoStatus.error(e.getMessage()); } finally { lockService.releaseLock(); } }
MigraMongo { public MigraMongoStatus migrate() { final boolean lockAcquired = lockService.acquireLock(); if ( !lockAcquired) { return MigraMongoStatus.lockNotAcquired(); } try { final List<MongoMigrationScript> migrationScriptsToApply = findMigrationScriptsToApply(); return migrate(migrationScriptsToApply); } catch (MongoMigrationException e) { logger.error("Migration Exception caught while migrating", e); return e.getStatus(); } catch (Exception e) { logger.error("Unknown Exception caught while migrating", e); return MigraMongoStatus.error(e.getMessage()); } finally { lockService.releaseLock(); } } }
MigraMongo { public MigraMongoStatus migrate() { final boolean lockAcquired = lockService.acquireLock(); if ( !lockAcquired) { return MigraMongoStatus.lockNotAcquired(); } try { final List<MongoMigrationScript> migrationScriptsToApply = findMigrationScriptsToApply(); return migrate(migrationScriptsToApply); } catch (MongoMigrationException e) { logger.error("Migration Exception caught while migrating", e); return e.getStatus(); } catch (Exception e) { logger.error("Unknown Exception caught while migrating", e); return MigraMongoStatus.error(e.getMessage()); } finally { lockService.releaseLock(); } } MigraMongo(
            MongoDatabase database,
            MigrationHistoryService migrationEntryService,
            LockService lockService,
            ScriptLookupService scriptLookupService); }
MigraMongo { public MigraMongoStatus migrate() { final boolean lockAcquired = lockService.acquireLock(); if ( !lockAcquired) { return MigraMongoStatus.lockNotAcquired(); } try { final List<MongoMigrationScript> migrationScriptsToApply = findMigrationScriptsToApply(); return migrate(migrationScriptsToApply); } catch (MongoMigrationException e) { logger.error("Migration Exception caught while migrating", e); return e.getStatus(); } catch (Exception e) { logger.error("Unknown Exception caught while migrating", e); return MigraMongoStatus.error(e.getMessage()); } finally { lockService.releaseLock(); } } MigraMongo(
            MongoDatabase database,
            MigrationHistoryService migrationEntryService,
            LockService lockService,
            ScriptLookupService scriptLookupService); void setAsyncInitializerFunction(Runnable function); MigraMongoStatus dryRun(); MigraMongoStatus migrate(); MigraMongoStatus migrateAsync(); MigraMongoStatus status(String fromVersion); MigraMongoStatus repair(String fromVersion, String toVersion); MigraMongoStatus rerun(String fromVersion, String toVersion); List<MigrationEntry> getMigrationEntries(); void destroyLocks(); }
MigraMongo { public MigraMongoStatus migrate() { final boolean lockAcquired = lockService.acquireLock(); if ( !lockAcquired) { return MigraMongoStatus.lockNotAcquired(); } try { final List<MongoMigrationScript> migrationScriptsToApply = findMigrationScriptsToApply(); return migrate(migrationScriptsToApply); } catch (MongoMigrationException e) { logger.error("Migration Exception caught while migrating", e); return e.getStatus(); } catch (Exception e) { logger.error("Unknown Exception caught while migrating", e); return MigraMongoStatus.error(e.getMessage()); } finally { lockService.releaseLock(); } } MigraMongo(
            MongoDatabase database,
            MigrationHistoryService migrationEntryService,
            LockService lockService,
            ScriptLookupService scriptLookupService); void setAsyncInitializerFunction(Runnable function); MigraMongoStatus dryRun(); MigraMongoStatus migrate(); MigraMongoStatus migrateAsync(); MigraMongoStatus status(String fromVersion); MigraMongoStatus repair(String fromVersion, String toVersion); MigraMongoStatus rerun(String fromVersion, String toVersion); List<MigrationEntry> getMigrationEntries(); void destroyLocks();  }