liquibase怎么在SpringBoot中使用

  介绍

这期内容当中小编将会给大家带来有关liquibase怎么在SpringBoot中使用,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

<强>一、引入依赖

先在pom文件里引入依赖

& lt; dependency>   ,& lt; groupId> org.liquibase   ,& lt; artifactId> liquibase-core   & lt;/dependency>

<强>二,指定配置文件位置

在代码中新建一个<代码> LiquibaseConfig> Liquibase> import  javax.sql.DataSource;   import  liquibase.integration.spring.SpringLiquibase;   import  org.springframework.context.annotation.Bean;   import  org.springframework.context.annotation.Configuration;      @ configuration   public  class  LiquibaseConfig  {      ,@ bean   ,public  SpringLiquibase  liquibase (DataSource 数据源),{   ,SpringLiquibase  liquibase =, new  SpringLiquibase ();   ,liquibase.setDataSource(数据源);   ,//指定的更新日志的位置,这里使用的一个主文件引用其他文件的方式   ,liquibase.setChangeLog(“类路径:liquibase/master.xml");   ,liquibase.setContexts(“开发、测试,production");   ,liquibase.setShouldRun(真正的);   ,return  liquibase;   ,}      }

<强>三、编写配置文件

目录结构:

 liquibase怎么在SpringBoot中使用“> </p> <p> <代码> src/main/资源> </代码下新建一个文件夹:<代码> liquibase> </代码,用来存放跟<代码> liquibase> </代码相关的文件。</p> <p> <强>的主人。xml </强> </p> <p>然后在<代码> liquibase </代码>文件夹下新建<代码>的主人。xml> </代码作为主文件。</p> <pre类= & lt; databaseChangeLog   xmlns=才能“http://www.liquibase.org/xml/ns/dbchangelog"   ,,xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance"   ,xsi: schemaLocation=癶ttp://www.liquibase.org/xml/ns/dbchangelog   ,,,http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"的在      ,& lt; includeAll 路径=發iquibase/变更/?relativeToChangelogFile=癴alse"/比;      & lt;/databaseChangeLog>

<代码> includeAll>

<代码> includeAll> 路径和<代码> relativeToChangelogFile>
文件AttributeDescriptionfileName import  requiredrelativeToChangelogFileIs文件路径相对于根目录的更新日志文件,而不是到类路径中。默认为“false",自1.9

<代码>路径>

<代码> relativeToChangelogFile>

<强>、

另在<代码> liquibase 文件夹下新建<代码>、文件夹用来存放changelog。

这里新建一个<代码>更新日志- 1.0。xml代码

 & lt; databaseChangeLog
  xmlns=才能“http://www.liquibase.org/xml/ns/dbchangelog"
  ,,xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance"
  ,xsi: schemaLocation=癶ttp://www.liquibase.org/xml/ns/dbchangelog
  ,,,http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"的在
  
  ,& lt; changeSet  id=?0190713 - 01 -“,作者=皊olo"比;
  & lt;才能createTable 表=皃roject_info"比;
  ,,& lt; column  name=皃roject_id",类型=皏archar(64)“,编码=皍tf8",讲话=跋钅縤d"比;
  ,,,& lt; constraints  primaryKey=皌rue", nullable=癴alse"/比;
  ,,& lt;/column>
  ,,& lt; column  name=皃roject_name",类型=皏archar(255)“,编码=皍tf8",讲话=跋钅棵帧?比;
  ,,& lt; column  name=皃roject_difficulty",类型=癴loat",编码=皍tf8",讲话=跋钅磕讯取?比;
  ,,& lt; column  name=癱ategory_id",类型=皏archar(64)“,编码=皍tf8",讲话=跋钅坷嘈屠嗄勘嗪拧?比;
  ,,& lt; column  name=皃roject_status",类型=癷nt(11)“,编码=皍tf8",讲话=跋钅孔刺?,0招募中,1,进行中,2已完成,3失败,4延期,5删除“/比;
  ,,& lt; column  name=皃roject_desc",类型=皏archar(512)“,编码=皍tf8",讲话=跋钅考蚪椤?比;
  ,,& lt; column  name=皃roject_creater_id",类型=皏archar(64)“,编码=皍tf8",讲话=跋钅看唇ㄕ遡d"/比;
  ,,& lt; column  name=皌eam_id",类型=皏archar(64)“,编码=皍tf8",讲话=跋钅克敉哦觟d"/比;
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null

liquibase怎么在SpringBoot中使用