From 9c6a4263bcf19e3ee7e847ee3c7c6e3c62e922c8 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 28 Jan 2025 06:13:10 +0100 Subject: [PATCH] cleanup and add the current schema-dump --- ...LiquibaseCompatibilityIntegrationTest.java | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/LiquibaseCompatibilityIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/LiquibaseCompatibilityIntegrationTest.java index 83795643..b56e1f5a 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/LiquibaseCompatibilityIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/LiquibaseCompatibilityIntegrationTest.java @@ -19,34 +19,49 @@ import javax.sql.DataSource; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS; -/* +/** Tests, if the Liquibase scripts can be applied to a database ionitialized with schemas + and test-data from a previous version. -1. clean the database: - pg-sql-reset +

The test needs a dump, ideally from the version of the lastest prod-release:

-2. populate the database: - ./gradlew bootRun --args='--spring.profiles.active=only-office' +
    +
  1. 1. clean the database:
    + pg-sql-reset -create the dump: - docker exec -i hsadmin-ng-postgres /usr/bin/pg_dump --create --column-inserts --disable-dollar-quoting -U postgres postgres >src/main/resources/db/changelog/prod-schema-only-office-with-test-data-full.sql +
  2. populate the database:
    + ./gradlew bootRun --args='--spring.profiles.active=only-office' + +
  3. create the reference-schema SQL-file with some initializations:
  4. +
    cat >src/test/resources/db/prod-only-office-schema-with-test-data.sql <
    + +
  5. add the dump to that reference-schema SQL-file:

    +
    docker exec -i hsadmin-ng-postgres /usr/bin/pg_dump \
    +                --column-inserts --disable-dollar-quoting -U postgres postgres \
    +               >>src/test/resources/db/prod-only-office-schema-with-test-data.sql
    +            
    +
+ +

The generated dump has to be committed to git and will be used in future test-runs + until it gets replaced at the next release.

*/ @Tag("importOfficeData") @DataJpaTest(properties = { - //"app.early-init.enabled=true", // Enable the early initializer - "spring.liquibase.enabled=false", // @Sql should go first, Liquibase will be initialized programmtically - "liquibase.liquibaseSchemaName=public", - "spring.datasource.url=${HSADMINNG_POSTGRES_JDBC_URL:jdbc:tc:postgresql:15.5-bookworm:///liquibaseCompatTC}", - "spring.datasource.username=${HSADMINNG_POSTGRES_ADMIN_USERNAME:admin}", - "spring.datasource.password=${HSADMINNG_POSTGRES_ADMIN_PASSWORD:password}", - "hsadminng.postgres.admin.username=postgres", - "hsadminng.postgres.restricted.username=restricted", - "hsadminng.superuser=${HSADMINNG_SUPERUSER:superuser-alex@hostsharing.net}" + "spring.liquibase.enabled=false" // @Sql should go first, Liquibase will be initialized programmtically }) @ActiveProfiles("only-office") @TestPropertySource(properties = "spring.liquibase.contexts=only-office") @DirtiesContext @Import({ Context.class, JpaAttempt.class, LiquibaseConfig.class}) -@Sql(value = "classpath:db/changelog/prod-schema-only-office-with-test-data-full.sql", executionPhase = BEFORE_TEST_CLASS) +@Sql(value = "/db/prod-only-office-schema-with-test-data.sql", executionPhase = BEFORE_TEST_CLASS) public class LiquibaseCompatibilityIntegrationTest extends CsvDataImport { @Autowired @@ -58,13 +73,8 @@ public class LiquibaseCompatibilityIntegrationTest extends CsvDataImport { @BeforeEach public void setup() throws Exception { - // Step 1: Run your custom SQL script -// final var populator = new ResourceDatabasePopulator(); -// populator.addScript(new ClassPathResource("db/changelog/prod-schema-only-office-with-test-data-part.sql")); -// populator.execute(dataSource); - - final var subjects = em.createNativeQuery("SELECT * FROM pg_catalog.pg_tables WHERE schemaname='public'").getResultList(); - assertThat(subjects).hasSize(2); + final var schemas = em.createNativeQuery("SELECT * FROM pg_catalog.pg_tables WHERE schemaname='public'").getResultList(); + assertThat(schemas).hasSize(2); final var liquibaseScripts = em.createNativeQuery("SELECT * FROM public.databasechangelog").getResultList(); assertThat(liquibaseScripts).hasSize(286);