springboot集成liquibase

简介

Liquibase社区是一个开源项目,帮助数百万开发人员快速管理数据库模式更改。

官网地址

链接: liquibase.

springboot集成

依赖

 <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

application.yml

server:
  port: 8080

spring:
  datasource:
    username: root
    password: Qloud@dev?666
    url: jdbc:mysql://192.168.2.42:32430/test?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
    driver-class-name: com.mysql.jdbc.Driver
  liquibase:
    enabled: true
    change-log: "classpath:/db/changelog/db.changelog-master.yaml"
    contexts: dev

db.changelog-master.yaml

这个有很多种配置方式
配置方式一

databaseChangeLog:
  - changeSet:
      id: 1
      author: nvoxland
      changes:
        - createTable:
            tableName: person
            columns:
              - column:
                  name: id
                  type: int
                  autoIncrement: true
                  constraints:
                    primaryKey: true
                    nullable: false
              - column:
                  name: firstname
                  type: varchar(50)
              - column:
                  name: lastname
                  type: varchar(50)
                  constraints:
                    nullable: false
              - column:
                  name: state
                  type: char(2)

配置方式二

#databaseChangeLog:
#  - include:
#      file: db/changelog/01-create-test-schema.xml
#  - include:
#      file: db/changelog/02-insert-test-data.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="db/changelog/01-create-test-schema.xml" relativeToChangelogFile="false"></include>
    <include file="db/changelog/02-insert-test-data.xml" relativeToChangelogFile="false"></include>

</databaseChangeLog>

在这里插入图片描述

示例 github地址

https://github.com/hkj123/liquibase.git

官方例子地址

https://docs.liquibase.com/tools-integrations/springboot/using-springboot-with-maven.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值