最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot整合liquibase的實(shí)現(xiàn)方法

 更新時間:2019年08月18日 11:06:15   作者:solocoder  
這篇文章主要介紹了SpringBoot整合liquibase的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

LiquiBase 是一個用于數(shù)據(jù)庫重構(gòu)和遷移的開源工具,通過日志文件的形式記錄數(shù)據(jù)庫的變更,然后執(zhí)行日志文件中的修改,將數(shù)據(jù)庫更新或回滾到一致的狀態(tài)。它的目標(biāo)是提供一種數(shù)據(jù)庫類型無關(guān)的解決方案,通過執(zhí)行schema類型的文件來達(dá)到遷移。其有點(diǎn)主要有以下:

  • 支持幾乎所有主流的數(shù)據(jù)庫,如MySQL, PostgreSQL, Oracle, Sql Server, DB2等;
  • 支持多開發(fā)者的協(xié)作維護(hù);
  • 日志文件支持多種格式,如XML, YAML, JSON, SQL等;
  • 支持多種運(yùn)行方式,如命令行、Spring集成、Maven插件、Gradle插件等。

liquibase 官方文檔地址: http://www.liquibase.org/documentation/index.html

一、引入依賴

先在 pom 文件里引入依賴

<dependency>
 <groupId>org.liquibase</groupId>
 <artifactId>liquibase-core</artifactId>
</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 dataSource) {
 SpringLiquibase liquibase = new SpringLiquibase();
 liquibase.setDataSource(dataSource);
 //指定changelog的位置,這里使用的一個master文件引用其他文件的方式
 liquibase.setChangeLog("classpath:liquibase/master.xml");
 liquibase.setContexts("development,test,production");
 liquibase.setShouldRun(true);
 return liquibase;
 }

}

三、編寫配置文件

目錄結(jié)構(gòu):

src/main/resources 下新建一個文件夾: liquibase ,用來存放跟 liquibase 相關(guān)的文件。

master.xml

然后在 liquibase 文件夾下新建 master.xml 作為主文件。

<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.1.xsd">

 <includeAll path="liquibase/changelogs/" relativeToChangelogFile="false"/>

</databaseChangeLog>

includeAll 標(biāo)簽可以把一個文件夾下的所有 changelog 都加載進(jìn)來。如果單個加載可以用 include 。

includeAll 標(biāo)簽里有兩個屬性: pathrelativeToChangelogFile 。

Attribute Description
file Name of the file to import required
relativeToChangelogFile Is the file path relative to the root changelog file rather than to the classpath. Defaults to "false" since 1.9

path (在 include 標(biāo)簽里是 file):指定要加載的文件或文件夾位置

relativeToChangelogFile :文件位置的路徑是否相對于 root changelog 是相對路徑,默認(rèn) false,即相對于 classpath 是相對路徑。

changelog

另在 liquibase 文件夾下新建 changelogs 文件夾用來存放 changelog。

這里新建一個 changelog-1.0.xml

<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.1.xsd">

 <changeSet id="20190713-01" author="solo">
  <createTable tableName="project_info">
   <column name="project_id" type="varchar(64)" encoding="utf8" remarks="項目id">
    <constraints primaryKey="true" nullable="false"/>
   </column>
   <column name="project_name" type="varchar(255)" encoding="utf8" remarks="項目名字"/>
   <column name="project_difficulty" type="float" encoding="utf8" remarks="項目難度"/>
   <column name="category_id" type="varchar(64)" encoding="utf8" remarks="項目類型類目編號"/>
   <column name="project_status" type="int(11)" encoding="utf8" remarks="項目狀態(tài), 0招募中,1 進(jìn)行中,2已完成,3失敗,4延期,5刪除"/>
   <column name="project_desc" type="varchar(512)" encoding="utf8" remarks="項目簡介"/>
   <column name="project_creater_id" type="varchar(64)" encoding="utf8" remarks="項目創(chuàng)建者id"/>
   <column name="team_id" type="varchar(64)" encoding="utf8" remarks="項目所屬團(tuán)隊id"/>
   <column name="create_time" type="bigint(64)" encoding="utf8" remarks="創(chuàng)建時間"/>
   <column name="update_time" type="bigint(64)" encoding="utf8" remarks="更新時間"/>
  </createTable>
 </changeSet>
 
 <changeSet id="20190713-02" author="solo">
  <createTable tableName="project_category" remarks="項目類型表">
   <column name="id" type="varchar(64)" remarks="項目類型id">
    <constraints primaryKey="true" nullable="false"/>
   </column>
   <column name="name" type="varchar(255)" remarks="類目類型名稱"/>
   <column name="status" type="int(11)" remarks="狀態(tài)。1正常,2刪除"/>
   <column name="remark" type="varchar(255)" remarks="備注"/>
  </createTable>
 </changeSet>

 <changeSet id="20190713-03" author="solo">
  <createTable tableName="project_like_user" remarks="項目點(diǎn)贊表">
   <column name="id" type="varchar(64)" remarks="主鍵id">
    <constraints primaryKey="true" nullable="false"/>
   </column>
   <column name="project_id" type="varchar(64)" remarks="項目id"/>
   <column name="user_id" type="varchar(64)" remarks="點(diǎn)贊的用戶id"/>
   <column name="status" type="int(11)" remarks="點(diǎn)贊狀態(tài),0 取消點(diǎn)贊,1點(diǎn)贊"/>
   <column name="type" type="int(11)" remarks="類型 1點(diǎn)贊"/>
   <column name="create_time" type="bigint(64)" remarks="創(chuàng)建時間"/>
   <column name="update_time" type="bigint(64)" remarks="更新時間"/>
  </createTable>
 </changeSet>

 <changeSet id="20190713-04" author="solo">
  <createTable tableName="project_picture" remarks="項目圖片表">
   <column name="id" type="varchar(64)" remarks="圖片id">
    <constraints primaryKey="true" nullable="false"/>
   </column>
   <column name="project_id" type="varchar(64)" remarks="項目id"/>
   <column name="picture_url" type="varchar(64)" remarks="圖片地址"/>
   <column name="picture_url_32" type="varchar(64)" remarks="圖片地址32位"/>
   <column name="picture_url_64" type="varchar(64)" remarks="圖片地址64位"/>
  </createTable>
 </changeSet>

</databaseChangeLog>

如果你的項目一開始就用了 liquibase,那可以像上面這樣寫,把建表語句都寫在 changelog 里。

如果一開始沒用,后期想引入 liquibase,可以把以前的數(shù)據(jù)庫導(dǎo)出成 sql,然后引入 sql 文件。方式如下:

<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.1.xsd">

 <include file="liquibase/changelogs/project.sql" relativeToChangelogFile="false"/>

</databaseChangeLog>

直接把項目導(dǎo)出的數(shù)據(jù)庫文件 project.sql 通過 include 標(biāo)簽引進(jìn)來。

以上就是 SpringBoot 整合 Liquibase 的全部內(nèi)容。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 基于Spring Security實(shí)現(xiàn)對密碼進(jìn)行加密和校驗(yàn)

    基于Spring Security實(shí)現(xiàn)對密碼進(jìn)行加密和校驗(yàn)

    我們在入門案例中,其實(shí)已經(jīng)是一個非常簡單的認(rèn)證,但是用戶名是寫死的,密碼也需要從控制臺查看,很顯然實(shí)際中并不能這么做,下面的學(xué)習(xí)中,我們來實(shí)現(xiàn)基于內(nèi)存模型的認(rèn)證以及用戶的自定義認(rèn)證,密碼加密等內(nèi)容,需要的朋友可以參考下
    2024-07-07
  • springboot項目關(guān)閉swagger如何防止漏洞掃描

    springboot項目關(guān)閉swagger如何防止漏洞掃描

    這篇文章主要介紹了springboot項目關(guān)閉swagger如何防止漏洞掃描,本文通過示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2024-05-05
  • 消息中間件詳解以及比較選擇

    消息中間件詳解以及比較選擇

    這篇文章主要介紹了消息中間件詳解以及比較選擇,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • Java實(shí)現(xiàn)簡單版貪吃蛇游戲

    Java實(shí)現(xiàn)簡單版貪吃蛇游戲

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)簡單版貪吃蛇游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • 使用IntelliJ IDEA查看類的繼承關(guān)系圖形(圖文詳解)

    使用IntelliJ IDEA查看類的繼承關(guān)系圖形(圖文詳解)

    這篇文章主要介紹了使用IntelliJ IDEA查看類的繼承關(guān)系圖形,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的工作或?qū)W習(xí)具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-03-03
  • Spring JDBC的使用詳解

    Spring JDBC的使用詳解

    這篇文章主要介紹了Spring JDBC的使用詳解,幫助大家更好的理解和學(xué)習(xí)使用SpringBoot框架,感興趣的朋友可以了解下
    2021-05-05
  • 詳解Java中的BigDecimal

    詳解Java中的BigDecimal

    這篇文章主要介紹了Java中的BigDecimal的使用方法,幫助大家更好的理解和使用Java,感興趣的朋友可以了解下
    2020-09-09
  • SpringBoot框架打包體積簡化過程圖解

    SpringBoot框架打包體積簡化過程圖解

    這篇文章主要介紹了SpringBoot框架打包體積簡化過程圖解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-05-05
  • 在SpringBoot中如何利用Redis實(shí)現(xiàn)互斥鎖

    在SpringBoot中如何利用Redis實(shí)現(xiàn)互斥鎖

    當(dāng)我們利用Redis存儲熱點(diǎn)數(shù)據(jù)時,突然就過期失效或者被刪除了,導(dǎo)致大量請求同時訪問數(shù)據(jù)庫,增加了數(shù)據(jù)庫的負(fù)載,為減輕數(shù)據(jù)庫的負(fù)載我們利用互斥鎖,本文重點(diǎn)介紹在SpringBoot中如何利用Redis實(shí)現(xiàn)互斥鎖,感興趣的朋友一起看看吧
    2023-09-09
  • JVM內(nèi)存溢出和內(nèi)存泄漏的區(qū)別及說明

    JVM內(nèi)存溢出和內(nèi)存泄漏的區(qū)別及說明

    這篇文章主要介紹了JVM內(nèi)存溢出和內(nèi)存泄漏的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-02-02

最新評論

天等县| 阿拉善右旗| 诸暨市| 武鸣县| 定安县| 临朐县| 岳普湖县| 淄博市| 枞阳县| 全南县| 航空| 志丹县| 皋兰县| 乌拉特后旗| 曲周县| 上蔡县| 微博| 固始县| 瓦房店市| 习水县| 沁源县| 津市市| 家居| 鹤壁市| 马尔康县| 东乌珠穆沁旗| 平潭县| 洮南市| 武功县| 南安市| 神池县| 长丰县| 南丰县| 古田县| 黄浦区| 新兴县| 渑池县| 莱州市| 沙湾县| 万源市| 城口县|