Reputation: 13791
I'm using FlywayDB for migrations on a Maven Java project. I am currently working to make it possible to deploy to Heroku.
On my local machine I am using the Maven Flyway plugin to run migrations:
$> mvn clean compile flyway:migrate
To do the same on heroku, I would normally try:
$> heroku run mvn flyway:migrate
However, mvn is not available after the build phase, so this yields an error (mvn: command not found
)
How can I run my flyway migrations on Heroku?
Upvotes: 8
Views: 2126
Reputation: 4857
According to the Heroku documentation using the Maven plugin is not recommended for running Flyway migrations.
Within the documentation there are two alternatives:
Upvotes: 2
Reputation: 10318
I think your best bet is to create a small class in your application that uses the FlywayDB Java API. It might look like this:
class Migrator {
public static void main(String[] args) throws Exception {
...
Flyway flyway = new Flyway();
flyway.setDataSource(url, user, password);
flyway.migrate();
}
}
Then create an entry in your Procfile
like this:
migrate: java -cp target/classes:target/dependency/* Migrator
And finally run it as needed with heroku run migrate
.
The reason Heroku does not include Maven in the slug (i.e. at runtime) is because the .m2
directory is not retained. If Maven were included, and you then ran a mvn
command, it would first have to download the internet. The .m2
directory is not retained because it would make the slug size too large.
Upvotes: 4