liquibase<插入> :插入当前日期 [英] liquibase <insert> : Insert current date

查看:246
本文介绍了liquibase<插入> :插入当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用liquibase插入标签插入数据.当我在value标签中输入数字时,它可以正常工作. 但是我正在寻找一个简单的函数,即使我没有将其作为表定义的一部分,它也可以处理默认日期(数据库的当前DateTime).

I am trying to insert data using liquibase insert tag. It works fine when I am inputing a number to value tag . But I am looking for a simple function that will take care of default date (current DateTime of database) even when I don't have it as part of my table definition.

例如:

<changeSet id="abc_1" author="Me">
<insert tableName="Emp" schemaName="XYZ">
    <column name="name" value="Me"/>
    <column name="create_date" value ="1328055111692"/>
    <column name="profile_last_update" value="currentDateTimeFunction"/>
    <column name="group_name" value="BlahBlah"/>
</insert>
</changeSet>

此处<column name="create_date" value ="1328055111692"/>正常工作,并且已插入数据库中.我也尝试使用<defaultValueDate><valueDate>,但它们还需要以指定格式输入一些日期.

here <column name="create_date" value ="1328055111692"/> works fine and it gets inserted in to the database. I also tried using <defaultValueDate> and <valueDate> but they also need some date input in specified format.

我正在寻找某些功能,例如 currentDateTimeFunction ,这些功能将根据我使用的数据库类型转换为UNIX_TIMESTAMP()或SYSDATE或now().请帮助我.

I am looking for some function like currentDateTimeFunction that would be converted to UNIX_TIMESTAMP() or SYSDATE or now() based on type of database I am using. Please help me.

谢谢你, 拉米亚

推荐答案

您要做的是使用

What you you will have to do is use changelog parameters and define a "now" or "current_timestamp" parameter that is replaced per database type.

<databaseChangeLog>的顶部(通常在<changeset>外部),添加属性的每个数据库定义,例如:

At the top of your <databaseChangeLog>, normally just outside your <changeset>, add per-database definitions of the property like:

  <property name="now" value="sysdate" dbms="oracle"/>
  <property name="now" value="now()" dbms="mysql"/>
  <property name="now" value="now()" dbms="postgresql"/>

然后在变更集中使用

<column name="Join_date" defaultValueFunction="${now}"/>

注意使用defaultValueFunction,它将使liquibase知道 不要将其解析为日期或引用它.

Notice the use of defaultValueFunction that will let liquibase know not to parse it as a date or quote it.

这篇关于liquibase&lt;插入&gt; :插入当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆