不再支持错误日期/时间值“未定义”的后续 postgres 迁移轰炸

问题描述

我正在尝试将我的应用程序(在 docker 中运行)连接到 postgres (9.6) docker 容器,并且在我的应用程序启动期间,我正在尝试使用 Sequelize (6.3.5) 应用我的所有数据库迁移,它工作得非常好当我将它连接到安装在我机器上的 postgres 但当我通过 docker-compose 运行应用程序时应用迁移时抛出以下错误

ERROR: date/time value "undefined" is no longer supported STATEMENT: SET client_min_messages TO warning;SET TIME ZONE INTERVAL 'undefined' HOUR TO MINUTE;

我已经使用 TZ 和 PGTZ 将 TIMEZONE 传递给 postgres 容器,但它似乎没有任何效果

我的 Sequelize 配置如下

config= {
    username: process.env.DB_USERNAME,password: process.env.DB_PASSWORD,database: process.env.DB_DATABASE,host: process.env.DB_HOST,port: process.env.DB_PORT,dialect: process.env.DB_CONNECTION,timezone: 'UTC'
  }

const sequelize = new Sequelize(
  config.database,config.username,config.password,config
)

我的迁移看起来像

module.exports = {
  up: (queryInterface,Sequelize) =>
    queryInterface.createTable('UserInsurances',{
      id: {
        allowNull: false,type: Sequelize.UUID,defaultValue: Sequelize.UUIDV1,primaryKey: true
      },userId: {
        allowNull: false,type: Sequelize.STRING(255)
      },insuranceId: {
        allowNull: false,type: Sequelize.STRING(50),unique: false
      },createdAt: {
        allowNull: false,type: Sequelize.DATE,defaultValue: new Date(0)
      },updatedAt: {
        allowNull: true,defaultValue: new Date(0)
      }
    }),down: (queryInterface,Sequelize) => queryInterface.dropTable('UserInsurances')
}

我的 docker-compose 如下所示

version: '3.0'
services:
  app:
    build:
      context: .
    container_name: insurance-mgmt
    environment:
      - DB_USERNAME
      - DB_PASSWORD
      - DB_DATABASE
      - "DB_HOST=db"
      - DB_PORT
      - DB_CONNECTION
    depends_on:
      - db
    restart: always
    ports:
      - '3000:3000'
    networks:
      - insurance-mgmt-network
  db:
    image: postgres:9.6
    container_name: insurance-mgmt-db
    environment:
      - "POSTGRES_USER=${DB_USERNAME}"
      - "POSTGRES_DB=${DB_DATABASE}"
      - "POSTGRES_PASSWORD=${DB_PASSWORD}"
      - "TZ=UTC"
      - "PGTZ=UTC"
    restart: always
    ports:
      - '5432'
    networks:
      - insurance-mgmt-network
networks:
  insurance-mgmt-network:
    driver: bridge

Sequelize 或 Postgres 中是否有我遗漏的配置

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)