Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get liquibase to skip table creation if it already exists with liquibase formatted sql?

This is what I have

--preconditions onFail:CONTINUE
--preconditions not tableExists tableName:QRTZ_CALENDARS schemaName:dbo
CREATE TABLE dbo.QRTZ_CALENDARS (
 SCHED_NAME VARCHAR (120)  NOT NULL ,
 CALENDAR_NAME VARCHAR (200)  NOT NULL ,
 CALENDAR IMAGE NOT NULL
) 
GO

Background. I'm using liquibase to setup a h2 database for test cases in java.

like image 937
Interlated Avatar asked Dec 28 '17 22:12

Interlated


Video Answer


1 Answers

Add a pre-Condition to your changeset for example:

<preConditions onFail="MARK_RAN">
    <not>
        <tableExists tableName="Table_name"/>
    </not>
</preConditions>
<createTable tableName="Table_name" >
    <column name="column1" type="NUMBER(20,0)"/>
</createTable>

like image 64
Somadev Avatar answered Sep 23 '22 12:09

Somadev