I have multitenant application and to do DB migration i have to loop over each and every tenant schema and migrate it,but when I use flyway.setSchema() in my code it is giving deprecation warning.

What is the alternative for it?

List<String> schemas = getExistingTenants();

for(int i=0;i < schemas.size(); i++)
{
Flyway flyway = Flyway.configure().dataSource(dataSource).load();
                    flyway.setSchemas(schemas.get(i));
            flyway.migrate();
}

2 Answers

2
lealceldeiro On

According to Flyway.setSchemas

Direct configuration of the Flyway object has been deprecated and will be removed in Flyway 6.0. Use Flyway.configure() instead.

In your case it would be something like:

List<String> schemas = getExistingTenants();

for(int i = 0; i < schemas.size(); i++) {
    Flyway flyway = Flyway.configure().dataSource(dataSource)
                          .schemas(schemas.get(i)) // <-- configure schemas here using the
                          .load();                 // FluentConfiguration object's method
    flyway.migrate();                              // `schemas(String... schemas)`
}

See also: FluentConfiguration.schemas(String... schemas).

2
Mark Rotteveel On

The proper way is to do this on the FluentConfiguration object just like you're already doing for the dataSource config:

Flyway flyway = Flyway.configure()
        .dataSource(dataSource)
        .schemas(schemas.get(i))
        .load();
flyway.migrate();

This is also documented on Flyway.setSchemas:

Deprecated: Direct configuration of the Flyway object has been deprecated and will be removed in Flyway 6.0. Use Flyway.configure() instead.

See also issue 1928.