liquibase---SpringBoot+Maven+liquibase

SpringBoot+Maven+liquibase

Configuration file

spring:
liquibase:
change-log: classpath:conf/liquibase/master.xml
enabled: true
drop-first: false
contexts: dev,prod
1
2
3
4
5
6
代码中

import liquibase.integration.spring.SpringLiquibase;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class LiquibaseConfig {

@Value("${spring.liquibase.enabled}")
private Boolean enable;

@Value("${spring.liquibase.drop-first}")
private Boolean deopFirst;

@Value("${spring.liquibase.contexts}")
private String contexts;

@Bean(name = "liquibase")
public SpringLiquibase springLiquibase(DataSource dataSource) {

SpringLiquibase springLiquibase = new SpringLiquibase();

springLiquibase.setDataSource(dataSource);
springLiquibase.setChangeLog("classpath:/conf/liquibase/master.xml");
springLiquibase.setShouldRun(enable);
springLiquibase.setDropFirst(deopFirst);
springLiquibase.setContexts(contexts);
return springLiquibase;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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.6.xsd">

<property name="now" value="now()" dbms="h2"/>
<property name="now" value="now()" dbms="mysql"/>

<property name="floatType" value="float4" dbms="postgresql, h2"/>
<property name="floatType" value="float" dbms="mysql, oracle, mssql, mariadb"/>

<= the include File "CLASSPATH: the conf / LiquiBase / ChangeLog / 20190626reportdata_addcloumn.xml" relativeToChangelogFile = "to false" />
</ databaseChangeLog>
subsequent file added, continue to append the line
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
14
15
20190626reportdata_addcloumn.xml

<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
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.6.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

<property name="autoIncrement" value="true"/>

<changeSet id="20190626reportdata_addcloumn" author="zzh">
<addColumn tableName="report_data">
<column name="status" type="int" remarks="状态" ></column>
</addColumn>
<addColumn tableName="report_data">
<column name="create_user_id" type="int" remarks="创建人id" ></column>
</addColumn>
<addColumn tableName="report_data">
<column name="check_user_id" type="int" remarks="确认人id" ></column>
</addColumn>
<addColumn tableName="report_data">
<column name="check_time" type="datetime" remarks="确认时间" ></column>
</addColumn>
</changeSet>
</databaseChangeLog>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

---------------------

Guess you like

Origin www.cnblogs.com/liyanyan665/p/11183019.html