Hi, I have a single sql script which has multiple DDL statement like,
create sequence
create table
alter table
For the very first time when I execute the sql script through springboot (dbchangelog.yaml), it works well, when i run again with application restart, it fails as the objects are already exists.
I can understand “object exists” failure can be handled with precondition, But, how could i handle multiple objects exists situation with precondition (“or” clause)?
It would be great that if anyone can help to clarify this please?
I recommend putting each DDL statement in a separate changeset (which is best practice if you are using Oracle) within the changelog, where each DDL statement can have it’s own unique precondition.
And, I have 100 plus mix of DDL statements, Is there a way that we can group new tables creation in single sql file with precondition to validate the table exists or not with any OR condition ?
Since i am using YAML format, Is there any sample precondition to review?
I am new to liquibase, it would be great if you could help.
I think you need to determine why Liquibase is running again and not finding that the changesets were already executed and recorded in the databasechangelog table.
Thanks for the reply, Daryl.
We wanted to validate/ verify few mandatory database objects (tables, sequences, constraints) which are required to make sure the application functioning with no issue. If any of those objects are not available or missing while bringing up , then want to recreate them on the fly through liquibase.
Why don’t you test the table/sequence existence inside the sql, before creating them?
For instance, you could do this:
declare
c int;
begin
select count(*) into c from user_tables where table_name = upper(‘<my_table_name>’);
if c = 0 then
execute immediate ‘create table <my_table_name> (…)’;
end if;
end;