LiquiBase预判断


预判断解决的问题:运行liquibase之前,DB中已经存在一个table,所以需要加上预判断;


完整的一个例子:


<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog

    <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="20151108112500" author="WWW">

<!-- 预判断-->
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="MYTABLE"/>
            </not>
        </preConditions>
        <createTable tableName=" MYTABLE">
           <column name="id" type="bigint" autoIncrement="true">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="title" type="varchar(100)"/>
            <column name="content" type="text">
                <constraints nullable="false" />
            </column>
            <column name="course_id" type="bigint"/>
            <column name="chapter_id" type="varchar(40)"/>
            <column name="user_id" type="bigint">
                 <constraints nullable="false" />
            </column>
             <column name="reply_count" type="int"/>
             <column name="same_ask_count" type="int"/>
             <column name="browse_count" type="int"/>
             <column name="time" type="bigint"/>
            <column name="status" type="varchar(10)"/>
            <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>
    </changeSet>
</databaseChangeLog>

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页