195. Spring Boot 2.0數據庫遷移:Flyway

 

【視頻&交流平臺】

à SpringBoot視頻http://t.cn/R3QepWG

à SpringCloud視頻http://t.cn/R3QeRZc

à Spring Boot源碼https://gitee.com/happyangellxq520/spring-boot

à Spring Boot交流平臺http://412887952-qq-com.iteye.com/blog/2321532

à Spring Boot Shiro視頻http://t.cn/R3QDMbh

à Spring Boot 2.0 之Spring Data 和JPAhttp://t.cn/R1pSojf

 歷史相關章節:

193. Spring Boot 數據庫遷移:概述

194. Spring Boot 數據庫遷移:Flyway

 

 

說明:

(1)Spring Boot 版本:2.0.0.RELEASE

(2)Flyway版本:5.0.7

 

前言:

       在上一節中spring boot使用了1.5.12.RELEASE,這裏我們要看看2.0.0.RELEASE的一個使用情況。大體的思路和上一篇是使用的,這裏我們在上一篇文章的基礎上進行調整。

 

一、版本說明

       這裏的Spring Boot版本使用的是2.0.0.RELEASE,那麼對於Flyway的版本是5.0.7,這裏從3.2.1到5.0.7版本的跨度還是很大的,至於多做了什麼改變,這裏就不詳細展開說明,有興趣的可以去了解下Flyway版本的升級情況。

 

二、準備工作

       在上一篇的基礎上,我們需要將數據庫中的所有表結構全部刪掉,爲什麼要全部刪除掉呢?在上面我們說到了Flyway的版本跨度是比較大的,這裏Flyway的管理版本的表名稱調整爲了flyway_schema_history(3.2.1的是schema_version)。

 

三、測試

       到這裏就可以運行測試了,順利的話,會在數據庫中看到之前的表和數據,另外就是Flyway管理版本信息的表:flyway_schema_history。

 

四、存放路徑說明

       由於我們使用了默認的路徑,如果你要修改默認的路徑的話,在2.0.0版本之後,使用的是如下的配置了:

spring.flyway.locations=classpath:/db/migration

5.1.12的版本的是:

flyway.locations=classpath:/db/migration

 

五、配置說明

       對於2.x的版本,Flyway的配置加上了spring的前綴,如下配置:

# FLYWAY (FlywayProperties)
spring.flyway.baseline-description= #
spring.flyway.baseline-on-migrate= #
spring.flyway.baseline-version=1 # Version to start migration
spring.flyway.check-location=true # Whether to check that migration scripts location exists.
spring.flyway.clean-disabled= #
spring.flyway.clean-on-validation-error= #
spring.flyway.dry-run-output= #
spring.flyway.enabled=true # Whether to enable flyway.
spring.flyway.encoding= #
spring.flyway.error-handlers= #
spring.flyway.group= #
spring.flyway.ignore-future-migrations= #
spring.flyway.ignore-missing-migrations= #
spring.flyway.init-sqls= # SQL statements to execute to initialize a connection immediately after obtaining it.
spring.flyway.installed-by= #
spring.flyway.locations=classpath:db/migration # The locations of migrations scripts.
spring.flyway.mixed= #
spring.flyway.out-of-order= #
spring.flyway.password= # JDBC password to use if you want Flyway to create its own DataSource.
spring.flyway.placeholder-prefix= #
spring.flyway.placeholder-replacement= #
spring.flyway.placeholder-suffix= #
spring.flyway.placeholders.*= #
spring.flyway.repeatable-sql-migration-prefix= #
spring.flyway.schemas= # schemas to update
spring.flyway.skip-default-callbacks= #
spring.flyway.skip-default-resolvers= #
spring.flyway.sql-migration-prefix=V #
spring.flyway.sql-migration-separator= #
spring.flyway.sql-migration-suffix=.sql #
spring.flyway.sql-migration-suffixes= #
spring.flyway.table= #
spring.flyway.target= #
spring.flyway.undo-sql-migration-prefix= #
spring.flyway.url= # JDBC url of the database to migrate. If not set, the primary configured data source is used.
spring.flyway.user= # Login user of the database to migrate.
spring.flyway.validate-on-migrate= #

 

Spring Boot 1.x的版本如下配置:

# FLYWAY (FlywayProperties)
flyway.baseline-description= #
flyway.baseline-version=1 # version to start migration
flyway.baseline-on-migrate= #
flyway.check-location=false # Check that migration scripts location exists.
flyway.clean-on-validation-error= #
flyway.enabled=true # Enable flyway.
flyway.encoding= #
flyway.ignore-failed-future-migration= #
flyway.init-sqls= # SQL statements to execute to initialize a connection immediately after obtaining it.
flyway.locations=classpath:db/migration # locations of migrations scripts
flyway.out-of-order= #
flyway.password= # JDBC password if you want Flyway to create its own DataSource
flyway.placeholder-prefix= #
flyway.placeholder-replacement= #
flyway.placeholder-suffix= #
flyway.placeholders.*= #
flyway.schemas= # schemas to update
flyway.sql-migration-prefix=V #
flyway.sql-migration-separator= #
flyway.sql-migration-suffix=.sql #
flyway.table= #
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.validate-on-migrate= #

 

 

 

點贊、轉發、評論,伸出你的雙手666…召喚你的小螞蟻:


你就是你,不一樣的小螞蟻!

 

 微信公衆號「SpringBoot最近更新:

 

206. Spring Boot 2.0 Swagger2:使用
205. Spring Boot 2.0 Swagger2:初識Swagger
當要離開的時候,我卻動情了
205. jetcache:你需要知道的小技巧
204. jetcache:在Spring Boot中怎麼玩?
遇見阿里,遇見自己
203. 阿里jetcache
202. 阿里Pandora Boot
微信公衆號讚賞功能升級了,真的假的?
《喜劇之王》「我養你啊」之人生選擇
201. Spring Boot JNDI:Spring Boot中怎麼玩JNDI
510阿里日,馬老師獻上最走心、最科技範兒證婚詞~
200. Spring Boot JNDI:在Tomcat中怎麼玩JNDI?
199. Spring Boot JNDI:這是蝦米?
Spring Boot 數據庫遷移系列
Spring Boot葵花寶典:初露鋒芒:MyBatis insert異常 Parameter 'name' not found
198. Spring Boot Flyway工作原理
21天習慣養成法則
197. Spring Boot 2.0數據庫遷移:Liquibase
196. Spring Boot 數據庫遷移:Liquibase
195. Spring Boot 2.0數據庫遷移:Flyway
194. Spring Boot 數據庫遷移:Flyway
193. Spring Boot 數據庫遷移:概述

 搜索springboot或者掃描以下二維碼即可關注:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章