Class JdbiFlywayMigration

java.lang.Object
org.jdbi.v3.testing.junit5.JdbiFlywayMigration
All Implemented Interfaces:
JdbiExtensionInitializer

public final class JdbiFlywayMigration extends Object implements JdbiExtensionInitializer
Use Flyway to create a database schema and/or preload a database instance.
  • Method Details

    • flywayMigration

      public static JdbiFlywayMigration flywayMigration()
      Returns an instance of JdbiFlywayMigration which can be configured and used as a JdbiExtensionInitializer.
      
           @RegisterExtension
           public JdbiExtension extension = JdbiExtension.h2()
                   .withInitializer(JdbiFlywayMigration.flywayMigration().withDefaultPath());
       
      Returns:
      A JdbiFlywayMigration instance.
    • withDefaultPath

      public JdbiFlywayMigration withDefaultPath()
      Use Default db/migration Flyway schema migration location. Migration scripts must be on the classpath.
      Returns:
      The instance itself for chaining method calls.
    • withPath

      public JdbiFlywayMigration withPath(String migrationPath)
      Add a custom flyway migration path.
      Parameters:
      migrationPath - The path to add. Must not be null.
      Returns:
      The instance itself for chaining method calls.
    • withPaths

      public JdbiFlywayMigration withPaths(String... migrationPaths)
      Add custom flyway migration paths.
      Parameters:
      migrationPaths - One or more paths to add. Must not be null.
      Returns:
      The instance itself for chaining method calls.
    • withSchema

      public JdbiFlywayMigration withSchema(String schema)
      Add flyway migration schema.
      Parameters:
      schema - A schema to add. Must not be null.
      Returns:
      The instance itself for chaining method calls.
    • withSchemas

      public JdbiFlywayMigration withSchemas(String... moreSchemas)
      Add flyway migration schemas.
      Parameters:
      moreSchemas - One or more schemas to add. Must not be null.
      Returns:
      The instance itself for chaining method calls.
    • cleanAfter

      @Deprecated public JdbiFlywayMigration cleanAfter()
      Deprecated.
      The default changed to true so this call actually does nothing.
      Will drop all objects in the configured schemas using Flyway after the test finishes.
      Returns:
      The instance itself for chaining method calls.
    • cleanAfter

      public JdbiFlywayMigration cleanAfter(boolean cleanAfter)
      Drop all objects in the configured schemas using Flyway after the test finishes.
      Parameters:
      cleanAfter - Set to false to avoid cleaning of the schema.
      Returns:
      The instance itself for chaining method calls.
    • initialize

      public void initialize(DataSource ds, Handle handle)
      Description copied from interface: JdbiExtensionInitializer
      Run initialization code before a test.
      Specified by:
      initialize in interface JdbiExtensionInitializer
      Parameters:
      ds - A reference to the managed DataSource which is controlled by a JdbiExtension.
      handle - The shared Handle which is returned from JdbiExtension.getSharedHandle().
      See Also:
    • cleanup

      public void cleanup(DataSource ds, Handle handle)
      Description copied from interface: JdbiExtensionInitializer
      Run cleanup code after a test.
      Specified by:
      cleanup in interface JdbiExtensionInitializer
      Parameters:
      ds - A reference to the managed DataSource which is controlled by a JdbiExtension.
      handle - The shared Handle which is returned from JdbiExtension.getSharedHandle().