I have a column called updated_time
it has a timestamp
data type assigned:
`updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
The problem is that currently, this column supports a second precision. I need it to be able to store a millisecond precision.
So, I have prepared a following Liquibase changeset:
{
"databaseChangeLog": [
{
"changeSet": {
"id": "1",
"changes": [
{
"modifyDataType": {
"columnName": "updated_time",
"newDataType": "timestamp(3)",
"tableName": "mytable"
},
"addDefaultValue": {
"columnDataType": "timestamp(3)",
"columnName": "updated_time",
"defaultValueComputed": "current_timestamp(3)",
"tableName": "mytable"
},
"addNotNullConstraint": {
"columnDataType": "timestamp(3)",
"columnName": "updated_time",
"tableName": "mytable"
}
}
]
}
}
]
}
Unfortunately, this changeset always fails.
Here is the reason:
2019-11-08 00:57:28.624 WARN [] 99326 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set ...
Reason: liquibase.exception.DatabaseException: Invalid default value for 'updated_time' [Failed SQL: (1067) ALTER TABLE maas.mytable MODIFY updated_time timestamp(3)]
I saw some posts regarding the fact that there were some changes to the timestamp
data type in version 5.7. That, by default, I cannot assign a non-zero (null) value to the timestamp
column. And, in order, to get it fixed, I'd have to make some changes to the server config itself.
Let's imagine that I have a limited access to the server and I can't simply go and modify the config, is there an elegant way of working around this issue in Liquibase?