How to create migration based on flyway java

I am using the flyway command line tool to handle my db migrations. So far, all migrations have been sql

Configuration file (only used options):

flyway.url=jdbc:postgresql://db.host flyway.user=user flyway.password=password flyway.table=flyway_migrations flyway.locations=filesystem:/home/........./sql/migrations flyway.sqlMigrationPrefix=update flyway.validateOnMigrate=false flyway.outOfOrder=true 

This works great.

But now I need to add one Java-based port. And I'm really puzzled. I can't find any examples. How to compile where to transfer java migrations.

I tried a simple migration class from official documentation:

 package db.migration; import org.flywaydb.core.api.migration.jdbc.JdbcMigration; import java.sql.Connection; import java.sql.PreparedStatement; /** * Example of a Java-based migration. */ public class V50_121_1__update_notes implements JdbcMigration { public void migrate(Connection connection) throws Exception { PreparedStatement statement = connection.prepareStatement("INSERT INTO test_user (name) VALUES ('Obelix')"); try { statement.execute(); } finally { statement.close(); } } } 

But what to do next? Tried compiling:

 javac -cp "./flyway-core-3.2.1.jar" V50_121_1__update_notes.java jar cf V50_121_1__update_dataNode_notes.jar V50_121_1__update_dataNode_notes.class 

And then, putting this jar in different locations has no effect.

information about the flyway - I do not see migration.

So, how to create a simple Java based migration. I would rather not use Maven, or something like that. Just a simple jar (???) file that is matched using the flyway command-line tool.

Thanks.

+5
source share
2 answers

Make sure your .class file is located in the db / migration directory inside the .jar file and the .jar file is placed in the / jars directory of your Flyway installations.

flyway.locations should also be installed on db.migration, file system: / home /........./ sql / migration

+3
source

Specify for .java files as .java como classpath : package_example.migrations

flyway.url = jdbc: postgresql: //db.host flyway.user = user flyway.password = password

flyway.table = flyway_migrations

flyway.locations = file system: /home/...../sql/migrations, classpath: pack_example.migrations

flyway.sqlMigrationPrefix = update flyway.validateOnMigrate = false flyway.outOfOrder = true

See the documentation link https://flywaydb.org/documentation/commandline/migrate

0
source

Source: https://habr.com/ru/post/1235215/


All Articles