Kevin Joymungol
Kevin Joymungol

Reputation: 1814

Spring boot get flyway configuration

I am running flyway on spring boot and I need to get the baseline version from spring boot code. The baseline version I have set in my application.yml file as below

  flyway:
    enabled: false
    baseline-version: 3

And in my spring boot code I am intializing my flyway as below

@Override
public void run(String... args) {

    Flyway flywaysftp = Flyway.configure()
            .locations("classpath:db/migration/sftp")
            .baselineVersion(?)
            .dataSource(dataSourceConfigSftp.dataSourceSftp().getJdbcUrl(), dataSourceConfigSftp.dataSourceSftp().getUsername(), dataSourceConfigSftp.dataSourceSftp().getPassword()).load();
}

I need to be able to set the baseline version of flywaysftp to the baseline version in my application.yml.

Is there a way to retrieve the baseline version from my application.yml using flyway libraries?

Upvotes: 0

Views: 159

Answers (1)

Abhinaba Chakraborty
Abhinaba Chakraborty

Reputation: 3671

You can use the Spring @Value like this:

@Component
public class MyClass{

  @Value("${flyway.baseline-version}")
  private String flywayBaselineVersion;

 ....
 ....

public void run(String... args) {

    Flyway flywaysftp = Flyway.configure()
            .locations("classpath:db/migration/sftp")
            .baselineVersion(flywayBaselineVersion)
            .dataSource(dataSourceConfigSftp.dataSourceSftp().getJdbcUrl(), dataSourceConfigSftp.dataSourceSftp().getUsername(), dataSourceConfigSftp.dataSourceSftp().getPassword()).load();
}
}

Upvotes: 3

Related Questions