问题
I use postgres DB, I faced an issue with liquibase adding interval to the current time as default value:
<property name="expired" value="current_timestamp + interval '60 days'"
dbms="postgresql"/>
<addColumn tableName="user">
<column name="expired" type="timestamp"
defaultValueDate="${expired}">
<constraints nullable="false"/>
</column>
</addColumn>
Expired property always returns current date without adding 60 days. Is it possible? Or is there some mistakes in value field? Thank you in advance.
回答1:
You need to use defaultValueComputed
for an expression.
But apparently there is a bug in Liquibase that prevents it from parsing an expression with current_timestamp
correctly. But using now()
seems to work:
<property name="expired" value="now() + interval '60 days'" dbms="postgresql"/>
<addColumn tableName="user">
<column name="expired" type="timestamp" defaultValueComputed="${expired}">
<constraints nullable="false"/>
</column>
</addColumn>
Unrelated, but: user
is a reserved keyword. It is a very bad idea to create a table with that name.
来源:https://stackoverflow.com/questions/52512435/liquibase-does-not-add-interval-to-current-timestamp