DatabaseSchemaVersionManager implements AppliedChangesProvider { public String getChangelogDeleteSql(ChangeScript script) { return String.format( "DELETE FROM " + changeLogTableName + " WHERE change_number = %d", script.getId()); } DatabaseSchemaVersionManager(QueryExecuter queryExecuter, String changeLogTableName); List<Long> getAppliedChanges(); String getChangelogDeleteSql(ChangeScript script); void recordScriptApplied(ChangeScript script); void setTimeProvider(CurrentTimeProvider timeProvider);  }
@Test public void shouldGenerateSqlStringContainingSpecifiedChangelogTableNameOnDelete() { DatabaseSchemaVersionManager schemaVersionManagerWithDifferentTableName = new DatabaseSchemaVersionManager(queryExecuter, "user_specified_changelog"); String updateSql = schemaVersionManagerWithDifferentTableName.getChangelogDeleteSql(script); assertThat(updateSql, Matchers.startsWith("DELETE FROM user_specified_changelog ")); }
@Test public void shouldGenerateSqlStringToDeleteChangelogTableAfterUndoScriptApplication() throws Exception { String sql = schemaVersionManager.getChangelogDeleteSql(script); String expected = "DELETE FROM changelog WHERE change_number = 99"; assertThat(sql, equalToIgnoringWhiteSpace(expected)); }