Spring Boot Flyway

来源:互联网 发布:生成二合一淘口令源码 编辑:程序博客网 时间:2024/06/10 12:50

发博词

Spring Boot AutoConfigure封装了两种类型的数据库版本控制工具:flyway和liquibase。简单比较了一下,flyway要方便很多。

配置详解

FLYWAY (FlywayProperties)

flyway.enabled=true # Enable flyway.
flyway.encoding= #
flyway.baseline-on-migrate= true#
flyway.baseline-description= #
flyway.baseline-version=1 # version to start migration
flyway.url= # JDBC url of the database to migrate. If not set, the primary configured data source is used.
flyway.user= # Login user of the database to migrate.
flyway.password= # JDBC password if you want Flyway to create its own DataSource
flyway.schemas= # schemas to update
flyway.table= schema_version#
flyway.target=迁移时使用的目标版本,默认为latest version,也就是全部脚本文件都执行
flyway.out-of-order= #
flyway.init-sqls= # SQL statements to execute to initialize a connection immediately after obtaining it.
flyway.check-location=false # Check that migration scripts location exists.
flyway.clean-on-validation-error= #
flyway.validate-on-migrate= #
flyway.ignore-failed-future-migration= #
flyway.locations=classpath:db/migration # locations of migrations scripts
flyway.placeholder-prefix= #
flyway.placeholder-replacement= #
flyway.placeholder-suffix= #
flyway.placeholders.*= #
flyway.sql-migration-prefix=V #
flyway.sql-migration-separator= #
flyway.sql-migration-suffix=.sql #

TIP

baseline

flyway.baseline-on-migrate: true
flyway.baseline-version: 0.1.0.2
flyway.baseline-description: sdfs

Spring Boot 1.5.6.RELEASE的flyway.baseline-version属性不管用;
这里写图片描述

placeholders

placeholders 提供了类似freemaker的模板功能,可以在脚本中写入 create table ${foo1}; 在flyway.setPlaceholders(map->{map.put(“foo1”,”table1”)}),替换脚本中的foo1 =》 table1

常用配置

flyway:  enabled: true   url: jdbc:mysql://localhost:3306/flyway_test  user: root  password: root  check-location: true  locations: classpath:db/migration/mysql  validate-on-migrate: true  clean-on-validation-error: true  target: 1.1.0.2  baseline-on-migrate: true  baseline-version: 0.1.0.2  baseline-description: sdfs

参考

Flyway:简单的数据库迁移工具
Official Documentation
Spring Boot Official Documentation
flyway在spring boot中的使用
Flyway学习笔记

原创粉丝点击