Prevent error when dropping not existing sequences, creating existing users
Liquibase has a failOnError attribute you can set to false on changeSets that include a call that could fail.
<changeSet failOnError="false"> <createSequence sequenceName="new_sequence"/></changeSet>
This allows you to have simple create user, create sequence, drop user, and drop sequence changeSets and if the statement throws an error because they users/sequences exist/don't exist they will still be marked as ran and the update will continue.
The downside of this approach is that it will also mark them as ran and continue if they error for some other reason (bad permissions, connection failure, invalid SQL, etc.) The more accurate approach is to use preconditions, like this:
<changeSet> <preconditions onFail="MARK_RAN"><not><sequenceExists/></not></preconditions> <createSequence name="new_sequence"/></changeSet>
There is no userExists precondition currently, but you can create custom preconditions or fall back to the precondition. See http://www.liquibase.org/documentation/preconditions.html for documentation
Write a function do_ddl similar to this and catch all exceptions you want to catch:
DECLARE allready_null EXCEPTION; PRAGMA EXCEPTION_INIT(allready_null, -1451);BEGIN execute immediate 'ALTER TABLE TAB MODIFY(COL NULL)';EXCEPTION WHEN allready_null THEN null; -- handle the errorEND;/