简体   繁体   English

如何构建基于 Java 的迁移迁移

[英]How to build flyway java-based migrations

I'm using flyway command-line tool to handle my db migrations.我正在使用 flyway 命令行工具来处理我的数据库迁移。 Till now all migrations are sql直到现在所有的迁移都是 sql

Config 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

That works perfectly.这完美地工作。

But for now I need to add one java-based migration.但是现在我需要添加一个基于 Java 的迁移。 And I'm really puzzled I can't find any How todo examples.我真的很困惑我找不到任何 How todo 示例。 How to compile, where to put java migrations.如何编译,将java迁移放在哪里。

I've tried 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 that jar to different locations, have no effect.然后把那个罐子放在不同的位置,没有效果。

flyway info - don't see the migration.飞行路线信息 - 看不到迁移。

So how to build the simplest java-based migration.那么如何构建最简单的基于java的迁移。 I will prefer not to use Maven, or something similar.我宁愿不使用 Maven 或类似的东西。 Just simple jar file(???) which is picked up by flyway command-line tool.只是简单的 jar 文件(???),由 flyway 命令行工具拾取。

Thank you.谢谢你。

Make sure your .class file is in a db/migration directory inside your .jar file file and that your .jar file is placed in the /jars directory of your Flyway installations.确保您的.class文件位于.jar文件中的db/migration目录中,并且您的.jar文件位于 Flyway 安装的/jars目录中。

flyway.locations should also be set to: flyway.locations也应设置为:

db.migration,filesystem:/home/........./sql/migrations

Specify for .java files as .java como.java文件指定为.java como

classpath : package_example.migrations类路径package_example.migrations

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

flyway.table=flyway_migrations

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

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

See the link for documentation https://flywaydb.org/documentation/commandline/migrate请参阅文档链接https://flywaydb.org/documentation/commandline/migrate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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