aycanadal
aycanadal

Reputation: 1146

How to utilize .java migration format

I have added Flyway 5.0.2 dependency to my build.gradle and set baseline-on-migrate: true to my application.yml.

I have the /resources/db/migration directory. The baseline entry is created in the flyway_schema_history. I can run migrations in .sql format too. But Flyway does not recognize my migrations in .java files. If I change the .java to .sql and change the content of the file from java to sql then all works fine. In the documentation it doesn't mention any special configuration or anything for the .java format.

How can I get Flyway to recognize my migrations in .java format?

An example java migration I have tried:

package db.migration;

import org.flywaydb.core.api.migration.spring.SpringJdbcMigration; 
import org.springframework.jdbc.core.JdbcTemplate;

public class V3__someMigration implements SpringJdbcMigration {

    @Override
    public void migrate(JdbcTemplate jdbcTemplate) throws Exception {

        System.out.println("migration v3");

    }

}

Upvotes: 1

Views: 523

Answers (2)

aycanadal
aycanadal

Reputation: 1146

The .java files shouldn't go under resources folder at all. It should go under /src/main/java/db/migration as it is explained in java-based-migrations section of the flyway documentation:

https://flywaydb.org/documentation/migrations#java-based-migrations

Upvotes: 2

Sushil Behera
Sushil Behera

Reputation: 916

Create your java file is created in below package src/main/resources/db/migration

Unless you changed below environment variable in flyway.properties FLYWAY_LOCATIONS=db.migration

Upvotes: -1

Related Questions