LiquiBase概述及(spring boot 入门配置)
2017-12-02 21:07
579 查看
官网:http://www.liquibase.org/
Liquibase是一个用于跟踪、管理和应用数据库变化的开源的数据库重构工具。它将所有数据库的变化(包括结构和数据)都保存在XML文件中,便于版本控制。
提供数据库比较功能,比较结果保存在XML中,基于该XML你可用Liquibase轻松部署或升级数据库。
以XML存储数据库变化,其中以作者和ID唯一标识一个变化(ChangSet),支持数据库变化的合并,因此支持多开发人员同时工作。
在数据库中保存数据库修改历史(DatabaseChangeHistory),在数据库升级时自动跳过已应用的变化(ChangSet)。
提供变化应用的回滚功能,可按时间、数量或标签(tag)回滚已应用的变化。通过这种方式,开发人员可轻易的还原数据库在任何时间点的状态。
可生成数据库修改文档(HTML格式)
提供数据重构的独立的IDE和Eclipse插件。
src/main/resources 目录下
config/liquibase/changelog/201712022057_add_entity_Base.xml
Liquibase是一个用于跟踪、管理和应用数据库变化的开源的数据库重构工具。它将所有数据库的变化(包括结构和数据)都保存在XML文件中,便于版本控制。
Liquibase具备如下特性:
不依赖于特定的数据库,目前支持包括Oracle/Sql Server/DB2/MySql/Sybase/PostgreSQL/Caché等12种数据库,这样在数据库的部署和升级环节可帮助应用系统支持多数据库。提供数据库比较功能,比较结果保存在XML中,基于该XML你可用Liquibase轻松部署或升级数据库。
以XML存储数据库变化,其中以作者和ID唯一标识一个变化(ChangSet),支持数据库变化的合并,因此支持多开发人员同时工作。
在数据库中保存数据库修改历史(DatabaseChangeHistory),在数据库升级时自动跳过已应用的变化(ChangSet)。
提供变化应用的回滚功能,可按时间、数量或标签(tag)回滚已应用的变化。通过这种方式,开发人员可轻易的还原数据库在任何时间点的状态。
可生成数据库修改文档(HTML格式)
提供数据重构的独立的IDE和Eclipse插件。
LiquiBase的spring boot 入门配置
pom.xml
<!-- https://mvnrepository.com/artifact/org.liquibase/liquibase-core --> <dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> <version>3.5.3</version> </dependency>
增加 LiquibaseConfig.java
package com.aop8.config; import javax.sql.DataSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import liquibase.integration.spring.SpringLiquibase; @Configuration public class LiquibaseConfig { @Bean public SpringLiquibase liquibase(DataSource dataSource) { SpringLiquibase liquibase = new SpringLiquibase(); liquibase.setDataSource(dataSource); liquibase.setChangeLog("classpath:config/liquibase/master.xml"); liquibase.setContexts("development,test,production"); liquibase.setShouldRun(true); return liquibase; } }
增加 master.xml
路径:src/main/resources 目录下 config/liquibase/master.xml<?xml version="1.0" encoding="utf-8"?> <databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> <include file="classpath:config/liquibase/changelog/201712022057_add_entity_Base.xml" relativeToChangelogFile="false"/> </databaseChangeLog>
201712022057_add_entity_Base.xml
路径:src/main/resources 目录下
config/liquibase/changelog/201712022057_add_entity_Base.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.1.xsd"> <property name="now" value="now()" dbms="mysql"/> <changeSet id="20171202205" author="WATER"> <preConditions onFail="MARK_RAN"> <not> <tableExists tableName="tb_member"/> </not> </preConditions> <createTable tableName="tb_member"> <column name="id" type="bigint" autoIncrement="true" remarks="主键" > <constraints primaryKey="true" nullable="false"/> </column> <column name="mobile" type="varchar(50)" remarks="手机号" > <constraints nullable="false" /> </column> <column name="real_name" type="varchar(50)" remarks="姓名" > <constraints nullable="false" /> </column> <column name="introduce" type="varchar(255)" remarks="说明" > <constraints nullable="false" /> </column> <column name="status" type="varchar(10)" remarks="账号状态" /> <column name="created_by" type="varchar(50)" remarks="创建人" > <constraints nullable="false"/> </column> <column name="created_date" type="timestamp" defaultValueDate="${now}" remarks="创建时间" > <constraints nullable="false"/> </column> <column name="last_modified_by" type="varchar(50)"/> <column name="last_modified_date" type="timestamp"/> </createTable> </changeSet> </databaseChangeLog>
相关文章推荐
- springboot【2】入门之配置文件
- SpringBoot入门-17(springboot集成mybatis注解形式增删查改properties配置)
- SpringBoot入门-9(springboot配置thymeleaf模板)
- Spring Boot 入门案例与配置说明
- SpringBoot入门-12(springboot配置servlet,利用代码实现)
- SpringBoot入门-21(springboot集成mybatis注解形式增删查改properties配置,利用@Provider实现动态SQL)
- Springboot入门-日志框架配置(转载)
- Spring Boot入门——web相关配置
- spring-boot入门(七)atomikos+druid+多数据源下的分布式事务配置
- Spring Boot 入门 - 进阶篇(7)- 自动配置(AutoConfigure)
- SpringBoot学习 —— 1、项目入门配置编
- Springboot入门-配置druid
- SpringCloud入门之Spring Boot多环境配置切换指南
- SpringBoot入门-15(springboot配置freemarker使用YML)
- spring boot (一)入门 启动、日志配置和快速构建
- 从入门到入门-Spring Boot-属性配置3
- Spring boot 系列 入门--配置
- Spring boot入门二 基础参数配置
- SpringBoot入门(五)——自定义配置
- SpringBoot 入门与配置