Class WithFlywaySchemaHistory

java.lang.Object
fr.ght1pc9kc.testy.jooq.WithFlywaySchemaHistory
All Implemented Interfaces:
org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension

public final class WithFlywaySchemaHistory extends Object implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback
Extension used to initialize a Flyway history in a database. A table is created into a schema provided by DatasourceExtension. History rows can be inserted with model FlywayVersion.

Example of use with default flyway history table


     private static final WithInMemoryDatasource wDataSource = WithInMemoryDatasource.builder()
             .setCatalog("test_db")
             .build();
     private static final WithFlywaySchemaHistory wFlywayHistory = WithFlywaySchemaHistory.builder(wDataSource)
             .addVersion(FlywayVersion.builder()
                              .version("1.0")
                              .script("V1_0__my_custom_script.sql")
                              .type(MigrationType.SQL)
                              .description("my custom script")
                              .checksum(1230145397)
                              .installedBy("test_db")
                              .installedOn(Instant.now())
                              .success(true)
                              .build)
             .build();

    @RegisterExtension
     static final ChainedExtension chain = ChainedExtension.outer(wDataSource)
             .append(wFlywayHistory)
             .register();
 

A customized history table name can also be defined.


     private static final WithInMemoryDatasource wDataSource = WithInMemoryDatasource.builder()
             .setCatalog("test_db")
             .build();
     private static final WithFlywaySchemaHistory wFlywayHistory = WithFlywaySchemaHistory.builder(wDataSource)
             .setTableName("my_custom_flyway_history")
             .addVersion(FlywayVersion.builder()
                              .version("1.0")
                              .script("V1_0__my_custom_script.sql")
                              .type(MigrationType.SQL)
                              .description("my custom script")
                              .checksum(1230145397)
                              .installedBy("test_db")
                              .installedOn(Instant.now())
                              .success(true)
                              .build)
             .build();

    @RegisterExtension
     static final ChainedExtension chain = ChainedExtension.outer(wDataSource)
             .append(wFlywayHistory)
             .register();
 
  • Method Details

    • beforeAll

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
    • beforeEach

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
      Specified by:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
    • builder

      Create a builder for this class.
      Parameters:
      datasourceExtension - DatasourceExtension to get the schema where Flyway history table will be created.
      Returns:
      WithFlywaySchemaHistory.WithFlywaySchemaHistoryBuilder.