.setString(1, app.getKey())
.get(r -> r.getString(1));
- // ignore if application only exists in xml and not in the db. It will be removed from the xml at later stage of the migration.
- if (applicationUuid == null) {
+ // skip migration if:
+ // - application only exists in xml and not in the db. It will be removed from the xml at later stage of the migration.
+ // - application contains no projects- it's already in a valid db state
+ List<String> projects = app.getProjects();
+ if (applicationUuid == null || projects.isEmpty()) {
return;
}
- String queryParam = app.getProjects().stream().map(uuid -> "'" + uuid + "'").collect(Collectors.joining(","));
+ String queryParam = projects.stream().map(uuid -> "'" + uuid + "'").collect(Collectors.joining(","));
Map<String, String> projectUuidsByKeys = context.prepareSelect(format(SELECT_PROJECTS_BY_KEYS, queryParam))
.list(r -> new AbstractMap.SimpleEntry<>(r.getString(1), r.getString(2)))
.stream()
private static final String EMPTY_XML = "<views></views>";
private static final String EMPTY_APP_XML = "<views>\n" +
- " <vw key=\"app1\" def=\"false\">\n" +
+ " <vw key=\"app1-key\" def=\"false\">\n" +
" <name><![CDATA[app1]]></name>\n" +
" <desc><![CDATA[]]></desc>\n" +
" <qualifier><![CDATA[APP]]></qualifier>\n" +
assertThat(db.countSql("select count(*) from app_branch_project_branch")).isZero();
}
+ @Test
+ public void skips_apps_that_exist_in_the_definition_but_does_not_exist_in_db() throws SQLException {
+ setupFullProject1();
+ insertViewsDefInternalProperty(EMPTY_APP_XML);
+
+ underTest.execute();
+
+ assertThat(db.select("select uuid from projects"))
+ .extracting(r -> r.get("UUID"))
+ .containsExactlyInAnyOrder(PROJECT_1_UUID);
+ assertThat(db.countSql("select count(*) from app_projects")).isZero();
+ assertThat(db.countSql("select count(*) from app_branch_project_branch")).isZero();
+ }
+
@Test
public void migrates_app_with_0_projects_in_views_definition() throws SQLException {
- setupProjectsAndApps();
+ setupFullProject1();
+ setupProject2();
+ setupApp1WithNoBranches();
insertViewsDefInternalProperty(EMPTY_APP_XML);
underTest.execute();
assertThat(db.select("select uuid from projects"))
.extracting(r -> r.get("UUID"))
- .containsExactlyInAnyOrder(PROJECT_1_UUID, PROJECT_2_UUID, APP_1_UUID, APP_2_UUID);
+ .containsExactlyInAnyOrder(PROJECT_1_UUID, PROJECT_2_UUID, APP_1_UUID);
assertThat(db.countSql("select count(*) from app_projects")).isZero();
assertThat(db.countSql("select count(*) from app_branch_project_branch")).isZero();
}