简体   繁体   中英

How to Implement flyway-play Java Migration

Is it possible to use Java migration script in flyway-play (3.0.0)?

SQL migrations work fine but when I place the example Java migration script into either app\\db\\migration\\V1_0_1__PopulateDatabase.java or into the same directory as the SQL script, it is not being recognised as a valid migration script.

Anyone tried this before?

As per the flyway-play README , Flyway migrations (scripts or Java migrations) need to be placed on the classpath at db/migration/${dbName} .

For example, imagine I have a database connection called default specified in application.conf like so:

db.default {
  driver=org.postgresql.Driver
  url="jdbc:postgresql://localhost/database"
}

In this case, I need to place sql migrations at conf/db/migration/default and Java migrations at app/db/migration/default .

In your case, you haven't included a database name in the Java migration's path. Whereas you've put the migration at app/db/migration/V1_0_1__PopulateDatabase.java , it should probably somewhere like app/db/migration/default/V1_0_1__PopulateDatabase.java .

You can also write your migrations in Scala and flyway-play will pick them up (it scans for both Scala and Java migrations). The flyway-play repo has an example Play app which does this: https://github.com/flyway/flyway-play/tree/master/playapp/app/db/migration/java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM