spring boot 整合 liquibase

  1. 添加依赖
<dependency>
   <groupId>org.liquibase</groupId>
   <artifactId>liquibase-core</artifactId>
   <version>3.8.3</version>
</dependency>
<dependency>
   <groupId>org.liquibase</groupId>
   <artifactId>liquibase-maven-plugin</artifactId>
   <version>3.8.3</version>
</dependency>

<plugin>
   <groupId>org.liquibase</groupId>
   <artifactId>liquibase-maven-plugin</artifactId>
   <version>3.8.3</version>
   <configuration>
      <propertyFile>src/main/resources/db/liquibase.properties</propertyFile>
   </configuration>
</plugin>
  1. 创建liquibase.properties 内容如下
url=jdbc:postgresql://127.0.0.1:5432/ems_factorymodeldb
username=name
password=password
driver=org.postgresql.Driver
outputChangeLogFile=src/main/resources/liquibase-outputChangeLog.xml
  1. 创建 db.changelog-master.xml
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
     http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

    <!--  版本更新迭代  -->
    <include file="classpath:db/changelogs/liquibase-changeLog.xml" relativeToChangelogFile="false"></include>

    <!--  现有数据  -->
    <includeAll path="./currentdatas" relativeToChangelogFile="true"/>

    <!--  数据初始化 脚本  -->
    <!-- <includeAll path="./defaultdatas" relativeToChangelogFile="true"/>-->
</databaseChangeLog>
  1. 增加配置
# liquibase
spring.liquibase.enabled=true
spring.liquibase.change-log=classpath:db/db.changelog-master.xml
posted @ 2021-08-18 08:06  脚下坚实  阅读(186)  评论(0)    收藏  举报