预判断解决的问题:运行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 >

<!-- 预判断-->
        <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>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-19
  • 2021-09-12
  • 2021-07-06
  • 2021-09-29
  • 2022-01-16
  • 2021-07-17
相关资源
相似解决方案