I am using Flyway version 5.2.4 in a scala project and have all my migration scripts are under src/main/resources/db/migrations with the following folder structure
main
-resources
--db
---migrations
----V1__example1.sql
----V2__example2.sql
----V3__scala_migration.scala
locations is set to db.migrations (Without any prefix. Flyway documentation says if no prefix is used then sql/java migrations are supported)
V1 and V2 seem to get picked up without issues. But V3 is being ignored. I tried adding a V3__java_migration.java as well and it made no difference. Did anyone have any kind luck adding non-sql migrations?
Here is the scala code in the migration
package db.migration
import org.flywaydb.core.api.migration.{ BaseJavaMigration, Context }
class V3__scala_migration extends BaseJavaMigration {
override def migrate(context: Context): Unit = {
val conn = context.getConnection
conn.createStatement().executeUpdate(
"""
|DROP TABLE IF EXISTS `users`;
|CREATE TABLE IF NOT EXISTS `users`
|`name` varchar(100) NOT NULL,
|`email` varchar(100) NOT NULL,
|PRIMARY KEY (`email`)
|)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|INSERT INTO `users` (`name`, `email`) ('john','[email protected]');
""".stripMargin)
}
}
You must move your Scala or Java migration scripts to the according directories.
For Scala this would be src/main/scala/db/migration
See here the documentation: https://flywaydb.org/documentation/migrations#discovery-1