spring boot 配置liquibase

java

@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");
        if (env.acceptsProfiles(Constants.SPRING_PROFILE_FAST)) {
            if ("org.h2.jdbcx.JdbcDataSource".equals(propertyResolver.getProperty("dataSourceClassName"))) {
                liquibase.setShouldRun(true);
                log.warn("Using '{}' profile with H2 database in memory is not optimal, you should consider switching to" +
                    " MySQL or Postgresql to avoid rebuilding your database upon each start.", Constants.SPRING_PROFILE_FAST);
            } else {
                liquibase.setShouldRun(false);
            }
        } else {
            log.debug("Configuring Liquibase");
        }
        return liquibase;
    }

pom

    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
         <version>3.3.2</version>
    </dependency>

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/20150906161010_add_entity_Base.xml" relativeToChangelogFile="false"/>

</databaseChangeLog>
<?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,h2"/>
    <property name="now" value="current_timestamp" dbms="postgresql"/>
    <property name="now" value="sysdate" dbms="oracle"/>

    <!--
         课程章节表
    -->
    <changeSet id="20150910102000" author="WATER">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="DLEDU_CHAPTER"/>
            </not>
        </preConditions>
        <createTable tableName="DLEDU_CHAPTER">
           <column name="id" type="bigint" autoIncrement="true">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" />
            </column>
            <column name="introduce" type="varchar(255)">
                 <constraints nullable="false" />
            </column>
            <column name="parent_id" type="bigint"/>
            <column name="content" type="varchar(40)"/>
            <column name="status" type="varchar(10)"/>
            <column name="course_id" type="bigint">
                <constraints nullable="false"/>
            </column>
            <column name="created_by" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="created_date" type="timestamp" defaultValueDate="${now}">
                <constraints nullable="false"/>
            </column>
            <column name="last_modified_by" type="varchar(50)"/>
            <column name="last_modified_date" type="timestamp"/>
        </createTable>

        <addForeignKeyConstraint baseColumnNames="course_id"
                                 baseTableName="DLEDU_CHAPTER"
                                 constraintName="fk_chapter_course_id"
                                 referencedColumnNames="id"
                                 referencedTableName="DLEDU_COURSE"/>

         <addForeignKeyConstraint baseColumnNames="content"
                                 baseTableName="DLEDU_CHAPTER"
                                 constraintName="fk_chapter_content"
                                 referencedColumnNames="id"
                                 referencedTableName="DLEDU_FILE"/>
    </changeSet>
</databaseChangeLog>
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页