create precondition when use the generateChangeLog

Hi,

is it possible to have a precondition on the xml when I use the generateChangeLog ?


we use an existing database and to manage change on this db we decided to use liquibase.

the problem is, the xml build by the generateChangeLog work correctly on an empty database.

on an existing database I have the error

  1. Caused by: liquibase.exception.DatabaseException: Error executing SQL CREATE TABLE foo (a TINYINT NULL, b TINYINT NULL): Table ‘foo’ already exists
each time I run the changeLog.

is it possible to have a precondition
  1.            
  2.                
  3.            
  4.        
on each changeSet when we generate a changeLog ?

thanks.

This is so handy in so many cases that I’d like to just concisely say something like

<createTable skipIfExists=“true” …>

Likewise for createIndex, addColumn, etc.

It would seem that you can, but what is your goal?

Would truncating the table serve just as well, or will the recreated table have a different structure?

What do you want to happen when the table does not yet exist? (Is that even possible?) Handle creation in this same changeset, or in a separate one?

As for using a single change set, what if your DBMS doesn’t support DDL transactions (e.g., MySQL), and the drop succeeds, but then the recreation somehow fails? Will you be able to recover from the intermediate state where the table is missing? (That’s one reason in favor of using a separate change set for each atomic change.)

What people will usually want is to first use one changeset to drop the table (or rename it, in case you later need to roll back), subject to a precondition that it already exists, then another changeset to create the new table.

I would like to drop table if it exists with my preconditions check and create again?

Is this possible with Liquibase in one change set, how can I do it?