programmatically generate liquibase-compare-file for prod-release 2025-01-28 #153

Merged
hsh-michaelhoennig merged 7 commits from feature/programmatically-generate-liquibase-compare-file into master 2025-01-30 09:36:37 +01:00
Showing only changes of commit 5b85a9463e - Show all commits

View File

@ -62,7 +62,6 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TE
public class LiquibaseCompatibilityIntegrationTest { public class LiquibaseCompatibilityIntegrationTest {
private static final String EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION = "hs-global-liquibase-migration-test"; private static final String EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION = "hs-global-liquibase-migration-test";
private static int initialChangeSetCount = 0;
@Autowired @Autowired
private DataSource dataSource; private DataSource dataSource;
@ -76,14 +75,29 @@ public class LiquibaseCompatibilityIntegrationTest {
@Test @Test
void migrationWorksBasedOnAPreviouslyPopulatedSchema() { void migrationWorksBasedOnAPreviouslyPopulatedSchema() {
// check the initial status from the @Sql-annotation // check the initial status from the @Sql-annotation
assertThatDatabaseIsInitializedWithLatestProdSchemasAndTestDataBySqlAnnotation(); final var initialChangeSetCount = assertProdReferenceStatusAfterRestore();
// run the current migrations and dump the result to the build-directory // run the current migrations and dump the result to the build-directory
runLiquibaseMigrationsWithContexts("only-office", "with-test-data"); runLiquibaseMigrationsWithContexts("only-office", "with-test-data");
dumpTo(new File("build/db/prod-only-office-schema-with-test-data.sql")); dumpTo(new File("build/db/prod-only-office-schema-with-test-data.sql"));
// then add another migration and test if it was applied // then add another migration and assert if it was applied
runLiquibaseMigrationsWithContexts("liquibase-migration-test"); runLiquibaseMigrationsWithContexts("liquibase-migration-test");
assertThatCurrentMigrationsGotApplied(initialChangeSetCount);
}
private int assertProdReferenceStatusAfterRestore() {
final var schemas = singleColumnSqlQuery("SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public'");
assertThat(schemas).containsExactly("databasechangelog", "databasechangeloglock");
final var liquibaseScripts1 = singleColumnSqlQuery("SELECT * FROM public.databasechangelog");
assertThat(liquibaseScripts1).hasSizeGreaterThan(285);
assertThat(liquibaseScripts1).doesNotContain(EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION);
final var initialChangeSetCount = liquibaseScripts1.size();
return initialChangeSetCount;
}
private void assertThatCurrentMigrationsGotApplied(final int initialChangeSetCount) {
final var liquibaseScripts = singleColumnSqlQuery("SELECT id FROM public.databasechangelog"); final var liquibaseScripts = singleColumnSqlQuery("SELECT id FROM public.databasechangelog");
assertThat(liquibaseScripts).hasSizeGreaterThan(initialChangeSetCount); assertThat(liquibaseScripts).hasSizeGreaterThan(initialChangeSetCount);
assertThat(liquibaseScripts).contains(EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION); assertThat(liquibaseScripts).contains(EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION);
@ -143,16 +157,6 @@ public class LiquibaseCompatibilityIntegrationTest {
assertThat(dir.isDirectory() || dir.mkdirs()).describedAs(dir + " cannot be created").isTrue(); assertThat(dir.isDirectory() || dir.mkdirs()).describedAs(dir + " cannot be created").isTrue();
} }
private void assertThatDatabaseIsInitializedWithLatestProdSchemasAndTestDataBySqlAnnotation() {
final var schemas = singleColumnSqlQuery("SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public'");
assertThat(schemas).containsExactly("databasechangelog", "databasechangeloglock");
final var liquibaseScripts = singleColumnSqlQuery("SELECT * FROM public.databasechangelog");
assertThat(liquibaseScripts).hasSizeGreaterThan(285);
assertThat(liquibaseScripts).doesNotContain(EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION);
initialChangeSetCount = liquibaseScripts.size();
}
@SneakyThrows @SneakyThrows
private void runLiquibaseMigrationsWithContexts(final String... contexts) { private void runLiquibaseMigrationsWithContexts(final String... contexts) {
liquibase.update( liquibase.update(