Liquibase sql precondition is not checked

橙三吉。 提交于 2021-01-29 07:54:38

问题


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)
)]

回答1:


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)
);


来源:https://stackoverflow.com/questions/41494270/liquibase-sql-precondition-is-not-checked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!