Run flyway migrations inside Java code during runtime

China☆狼群 提交于 2021-01-03 09:53:35

问题


I want to be able to run Flyway migrations inside my Java code during runtime, is there a way of achieving this? I can't seem to be able to find it in the docs. I'm using a SQLite database (if this matters at all).


回答1:


Flyway::migrate()

Call Flyway::migrate.

To quote the 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();

    }
}


来源:https://stackoverflow.com/questions/52728391/run-flyway-migrations-inside-java-code-during-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!