Liquibase: how to keep not-null-constraint and default value when running modifyDataType?

30 Views Asked by At

What I've tried is to put the constraint and default value in the attribute newDataType, but all is ignored after the word datetime.

<modifyDataType tableName="my_table" columnName="my_column" newDataType="datetime DEFAULT current_timestamp() NOT NULL"/>

I also tried to solve this by adding the following line to the change set.

<addNotNullConstraint tableName="my_table" columnName="my_column" columnDataType="datetime" defaultNullValue="CURRENT_TIMESTAMP"/>

When I change datetime into timestamp all is working as expected.

"Fun" fact is that for older versions (Liquibase 3) when adding a space in front of datetime apparently a condition is not met and the stripping of the value of the attribute newDateType doesn't kicks in.

The version of Liquibase that I use is version: 4.26.0. The database on which the changesets are run at is MariaDB 11.3.2

0

There are 0 best solutions below