如何在flyway创建的Postgresql

如何在flyway创建的Postgresql

本文介绍了如何在flyway创建的Postgresql JDBC连接上设置时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个postgresql数据库,可以将脚本部署为使用flyway。我使用Maven flyway插件针对目标数据库启动数据库构建。在该版本中,我具有执行以下操作的脚本:

 创建表my_table(
my_date_time时间戳,时区不为null
);

插入my_table(my_date_time)
中,选择 2000-01-01;

postgresql数据库时区设置为UTC。我的客户端计算机(运行maven / flyway构建)正在运行CEST(UTC + 2:00)。



当脚本运行时,数据库解释上面的字符串文字为'1999-12-31 22:00:00 + 00:00'并将其写入存储。



似乎flyway创建的jdbc客户端连接不是将其客户端时区设置为UTC,但是正在使用timstamp字符串并将其解释为 2000-01-01 00:00:00 + 02:00。



如何我可以在通过flyway到UTC创建的jdbc连接上设置客户端时区吗?



如果我将本地计算机时区更改为UTC,问题就消失了,但是我宁愿不这样做吗?



解决方案

同事建议以下内容

  mvn -Duser.timezone = UTC飞行路线:迁移


I have a postgresql database that I deploy scripts to using flyway. I use the maven flyway plugin to launch the database build against the target database. In that build I have scripts that do things like:

create table my_table(
my_date_time timestamp with time zone not null
);

insert into my_table(my_date_time)
select '2000-01-01';

The postgresql database timezone is set to UTC. My client machine (that runs the maven/flyway build) is running CEST (UTC+2:00).

When the scripts run, the database interprets the string literal above as '1999-12-31 22:00:00+00:00' and writes that to storage.

It seems that the jdbc client connection created by flyway is not setting its client timezone to UTC, but is taking the timstamp string and interpreting it as '2000-01-01 00:00:00+02:00'.

How can I set the client timezone on the jdbc connection created by flyway to UTC? Is there a setting that can be placed in my flyway.conf file?

If I change my local machine timezone to UTC the problem goes away, but I'd rather not do that on my development workstation.

解决方案

A colleague suggested the following

mvn -Duser.timezone=UTC flyway:migrate

这篇关于如何在flyway创建的Postgresql JDBC连接上设置时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 15:35