当前位置:Gxlcms > 数据库问题 > Flyway详解以及Springboot集成Flyway, 数据库脚本版本管理

Flyway详解以及Springboot集成Flyway, 数据库脚本版本管理

时间:2021-07-01 10:21:17 帮助过:281人阅读

dependency> <groupId>org.flywaydb</groupId> <artifactId>flyway-core</artifactId> <version>5.2.1</version> </dependency>

2、新建一个maven的Springboot项目,在配置文件中配置数据源信息:

server.port=8088
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/testdb
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

3、在classpath下新建/db/migration文件夹,并创建sql脚本文件:

use testdb;
 
CREATE TABLE person (
  id int(11) NOT NULL AUTO_INCREMENT,
  first varchar(100) NOT NULL,
  last varchar(100) NOT NULL,
  dateofbirth DATE DEFAULT null,
  placeofbirth varchar(100) not null,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

4、启动springboot项目:

技术图片

加载了sql脚本 。

5、查看数据库:

生成了flyway-schema-history表,这个版本默认是这个表,如果想自己指定schema表的命,可以设置:

flyway.tableflyway

6:flyway的一些其他配置:

spring.flyway.baseline-description对执行迁移时基准版本的描述.
spring.flyway.baseline-on-migrate当迁移时发现目标schema非空,而且带有没有元数据的表时,是否自动执行基准迁移,默认false.
spring.flyway.baseline-version开始执行基准迁移时对现有的schema的版本打标签,默认值为1.
spring.flyway.check-location检查迁移脚本的位置是否存在,默认false.
spring.flyway.clean-on-validation-error当发现校验错误时是否自动调用clean,默认false.
spring.flyway.enabled是否开启flywary,默认true.
spring.flyway.encoding设置迁移时的编码,默认UTF-8.
spring.flyway.ignore-failed-future-migration当读取元数据表时是否忽略错误的迁移,默认false.
spring.flyway.init-sqls当初始化好连接时要执行的SQL.
spring.flyway.locations迁移脚本的位置,默认db/migration.
spring.flyway.out-of-order是否允许无序的迁移,默认false.
spring.flyway.password目标数据库的密码.
spring.flyway.placeholder-prefix设置每个placeholder的前缀,默认${.
spring.flyway.placeholder-replacementplaceholders是否要被替换,默认true.
spring.flyway.placeholder-suffix设置每个placeholder的后缀,默认}.
spring.flyway.placeholders.[placeholder name]设置placeholder的value
spring.flyway.schemas设定需要flywary迁移的schema,大小写敏感,默认为连接默认的schema.
spring.flyway.sql-migration-prefix迁移文件的前缀,默认为V.
spring.flyway.sql-migration-separator迁移脚本的文件名分隔符,默认__
spring.flyway.sql-migration-suffix迁移脚本的后缀,默认为.sql
spring.flyway.tableflyway使用的元数据表名,默认为schema_version
spring.flyway.target迁移时使用的目标版本,默认为latest version
spring.flyway.url迁移时使用的JDBC URL,如果没有指定的话,将使用配置的主数据源
spring.flyway.user迁移数据库的用户名
spring.flyway.validate-on-migrate迁移时是否校验,默认为true.

版权声明:本文为CSDN博主「Jennire_Q」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qiuhao9527/article/details/81070482

Flyway详解以及Springboot集成Flyway, 数据库脚本版本管理

标签:元数据   自己   原创   行迁移   his   版本管理   文件中   def   jdbc   

人气教程排行