radcortez / flyway-junit5-extensions

Flyway JUnit 5 Extension to clean / migrate your database in tests.
Apache License 2.0
19 stars 1 forks source link

A way to pass arbitrary flyway config to @FlywayTest #367

Open mohamnag opened 1 year ago

mohamnag commented 1 year ago

I have seen other issues regarding using a file or environment variables to pass configurations to flyway. this might work in some scenarios but in specific cases they are not practical or need much additional effort. like when one has many tests which each need to be configured differently.

A very effective solution (which can also be potentially done very easily) is that one can set an arbitrary map on the @FlywayTest to just pass configurations to the instance that is created later. What do you think?

radcortez commented 1 year ago

My recommendation is to have something that accepts a properties file path from the classpath and then load it in the Flyway instance (like we already do with additionalLocations).

Would you like to submit a PR?

mohamnag commented 1 year ago

well having a file separate from the test is an impractical solution. I have used wiremock with this setup and soon two problems emerge:

  1. becomes hard to understand the setup of test as config relies separately in a different file (the properties file)
  2. becomes hard to change those config files as people start reusing one properties file from multiple tests.

so what I was thinking of, is a kind of passing config like following pseudo-code:

@FlywayTest(
    value = @DataSource(SomeDataSourceProvider.class),
    additionalLocations = {"classpath:some/sql/files/"},
    config = {
        "key"="value",
        "createSchemas"="false",
    }
)

a better variation is that a config file is also allowed to be passed in (mainly for common config parts) and that additional key value pair defined directly on the annotation just overrides things that should be changed for specific test. for example:

@FlywayTest(
    value = @DataSource(SomeDataSourceProvider.class),
    configFile = "classpath:/some/dir/flyway.conf"
    configOverride = {
        "key"="value",
        "createSchemas"="false",
    }
)

I could go on and prepare something for this case as it also matches my usage pattern. WDYT?

radcortez commented 1 year ago

Well, I want to avoid translating all the config into the annotation. With a file, you would only need a single parameter in the annotation, and it would be easier to hand over to the Flyway instance. I guess that we could add a repeatable @Config annotation with key / value.