每一个不曾起舞的日子都是对生命的辜负。
Flyway is an open-source database migration tool. It strongly favors simplicity and convention over configuration. It is based around just 6 basic commands: Migrate, Clean, Info, Validate, Baseline and Repair. Migrations can be written in SQL (database-specific syntax (such as PL/SQL, T-SQL, …) is supported) or Java (for advanced data transformations or dealing with LOBs). It has a Command-line client. If you are on the JVM, we recommend using the Java API (also works on Android) for migrating the database on application startup. Alternatively, you can also use the Maven plugin, Gradle plugin, SBT plugin or the Ant tasks. And if that not enough, there are plugins available for Spring Boot, Dropwizard, Grails, Play, Griffon, Grunt, Ninja and more!
需要在pom.xml文件中加入flywaydb的插件:
|
|
配置方法一:在pom.xml里配置
|
|
配置方法二:外部的配置文件来配置
|
|
配置方法三:执行mvn时通过指定参数flyway.configFile的值来指定配置文件
|
|
配置方法四:使用外部配置文件的方式进行配置,默认的flyway.properties文件和pom.xml在相同的路径下
|
|
Migrate
flyway的最重要的功能当然是完成数据库迁移了,使用mvn flyway:migrate命令就可以方便的帮助我们执行flyway.locations目录中定义的migration任务。由于我们的使用了外部的flyway配置文件,因此在执行migration任务时需要加上参数flyway.properties来指定配置文件的位置。所以,在我们的工程中需要执行的任务为:
mvn flyway:migrate -Dflyway.configFile=localPath/flyway.properties
其中localPath/
为flyway.properties
文件在本地的路径。
Clean
如果我们想初始化数据库,删除所有的表和数据,那么只需要执行命令:
mvn flyway:clean
Info
如果我们想知道所有migration的详细信息,可以通过执行下面命令来打印信息:
mvn flyway:info
执行之后,Terminal中会打印出所有migration的详细信息,其中包括版本号,描述,执行时间,以及状态.
Validate
mvn flyway:validate
用来执行已经执行过的migration任务.
Baseline
mvn flyway:baseline
用来回滚数据库到一个配置文件中设定好的baseline.
Repair
mvn flyway:repair
用来删除执行失败的migration任务.
更多关于flyway的详细用法,请参见其官方文档。