Zeus
Zeus

Reputation: 6566

Liquibase sql precondition is not checked

I have multiple changelogs and one of the change log has the precondition on it to check if table exists, if so, skip running the migration.

My change log file

--liquibase formatted sql

--preconditions onFail:MARK_RAN onError:MARK_RAN
--precondition-sql-check expectedResult:0 select COUNT(*) C from dba_tables where UPPER(table_name) = 'PERSON' and upper(owner) = 'INT'

--changeset nvoxland:3
create table int.person (
  id int not null primary key,
  firstname varchar(80),
  lastname varchar(80) not null,
  state varchar(2)
);

The precondition is never checked, it directly goes to creating the 'person' table. I have this table in this db instance because of the refresh, i'd like this migration to run if it does not exist and skip on precondition.

error I get

C:\Project\Tools\liquibase-3.5.3-bin>liquibase --driver=oracle.jdbc.driver.Oracl
eDriver --changeLogFile=C:\Project\Tools\Migrations\liquibase\master.xml --url="
jdbc:oracle:thin:@database:1521:name" --username=user --password=dpass migrate
Unexpected error running Liquibase: ORA-00955: name is already used by an existi
ng object
 [Failed SQL: create table int.person (
  id int not null primary key,
  firstname varchar(80),
  lastname varchar(80) not null,
  state varchar(2)
)]

Upvotes: 2

Views: 2792

Answers (2)

Bhanu Sharma
Bhanu Sharma

Reputation: 121

-- noinspection SqlNoDataSourceInspectionForFile

can cause the same problem

remove it

Upvotes: 0

Zeus
Zeus

Reputation: 6566

Never mind, I solved this myself

The ordering of the precondition was important, updated to the following, it ran fine this time

--liquibase formatted sql

--changeset nvoxland:3
--preconditions onFail:MARK_RAN onError:MARK_RAN
--precondition-sql-check expectedResult:0 select COUNT(*) C from dba_tables where UPPER(table_name) = 'PERSON' and upper(owner) = 'INT'
create table int.person (
  id int not null primary key,
  firstname varchar(80),
  lastname varchar(80) not null,
  state varchar(2)
);

Upvotes: 1

Related Questions