【问题标题】:Run flyway migrations inside Java code during runtime在运行时在 Java 代码中运行 flyway 迁移
【发布时间】:2019-03-14 16:00:02
【问题描述】:

我希望能够在运行时在我的 Java 代码中运行 Flyway 迁移,有没有办法实现这一点?我似乎无法在文档中找到它。我正在使用 SQLite 数据库(如果这很重要的话)。

【问题讨论】:

标签: java jdbc flyway


【解决方案1】:

Flyway::migrate()

致电Flyway::migrate

引用documentation

package foobar;

import org.flywaydb.core.Flyway;

public class App {
    public static void main(String[] args) {

        // Create the Flyway instance and point it to the database
        Flyway flyway = 
                Flyway.configure()
                      .dataSource( "jdbc:h2:file:./target/foobar" , "scott" , "tiger" )  // (url, user, password)
                      .load()                                                            // Returns a `Flyway` object.
        ;

        // Start the migration
        flyway.migrate();

    }
}

【讨论】:

    猜你喜欢
    • 2016-12-12
    • 2017-08-16
    • 2020-06-28
    • 2015-09-21
    • 2020-08-17
    • 2020-01-02
    • 2017-05-31
    • 2017-03-03
    • 2011-03-13
    相关资源
    最近更新 更多