Precondition to Check Whether Column is Nullable

I am using the liquibase XML DSL to modify primary/foreign keys on tables in a database. The target RDBMS systems are oracle and sql server. I want a precondition check in my changeset to check whether the column is nullable or not. If it does allow nulls, then I want to alter the column and make it not null. (Of course I will make sure the column has data before attempting to make it not null.) SQL Server appears to allow (or ignore) altering a column that is already not null to not null (and vice-versa in regards to a nullable column). Oracle, on the other hand, does not appear to allow this and generates an error. 

If there’s no cleaner/better way to check whether a column is nullable or not (wouldn’t know constraint name so couldn’t use the constraint precondition), I’ll leverage the failOnError=“false” attribute.

Is there a better way in liquibase to check a column to determine whether it is nullable or not.

Thank you.

There isn’t a built-in precondition that will check that, but you could either use the precondition and query the metadata tables in the check, or write your own extension that can check nullability without needing a constraint name. has some documentation on writing an extension. The advantage with an extension is that then you don’t need to keep writing the SQL in each precondition and can use the liquibase snapshot java APIs to get at the metadata without figuring out the SQL.

If you wanted to send a pull request for a new precondition in the main liquibase code, I would certainly look at incorporating it as well.