javascriptsequelize-cli

sequelize db:migrate hanging


I am trying to get my models to migrate to the postgress db I am using, which is hosted locally and I confirmed is up and running fine.

When I run sequelize db:migrate it says

Loaded configuration file "config\config.json"
Using environment "development"

then nothing, I can't type into the console or anything, it just sits there until I ctrl+C out of it

I tried reverting all the changes I had made to the models and migrations files in case there was an issue there and it didn't help.

edit: I also tried reinstalling the sequelize-cli through npm and that also did not fix the issue

here is the model and migration code in case that is the issue

model:

'use strict';
module.exports = (sequelize, DataTypes) => {
  const Contract = sequelize.define('Contract', {
    buyout: DataTypes.DOUBLE,
    collateral: DataTypes.DOUBLE,
    contract_id: {type:DataTypes.INTEGER,allowNull: false,},
    date_expired: {type:DataTypes.DATE,allowNull: false,},
    date_issued: {type:DataTypes.DATE,allowNull: false,},
    days_to_complete: DataTypes.INTEGER,
    end_location_id: DataTypes.BIGINT,
    for_corporation: DataTypes.BOOLEAN,
    issuer_corporation_id: {type:DataTypes.INTEGER,allowNull: false,},
    issuer_id: {type:DataTypes.INTEGER,allowNull: false,},
    price: DataTypes.DOUBLE,
    reward: DataTypes.DOUBLE,
    start_location_id: DataTypes.BIGINT,
    title: DataTypes.STRING,
    type: {type:DataTypes.STRING,allowNull: false,},
    volume: DataTypes.DOUBLE
  });
  Contract.associate = (models) => {
    Contract.hasMany(models.ContractItem,{
      foreignKey: 'contract_id'
    });
  };
  return Contract;
};

migration

'use strict';
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('Contracts', {
      buyout: {
        type: Sequelize.DOUBLE
      },
      collateral: {
        type: Sequelize.DOUBLE
      },
      contract_id: {
        allowNull: false,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      date_expired: {
        allowNull: false,
        type: Sequelize.DATE
      },
      date_issued: {
        allowNull: false,
        type: Sequelize.DATE
      },
      days_to_complete: {
        type: Sequelize.INTEGER
      },
      end_location_id: {
        type: Sequelize.BIGINT
      },
      for_corporation: {
        type: Sequelize.BOOLEAN
      },
      issuer_corporation_id: {
        allowNull: false,
        type: Sequelize.INTEGER
      },
      issuer_id: {
        allowNull: false,
        type: Sequelize.INTEGER
      },
      price: {
        type: Sequelize.DOUBLE
      },
      reward: {
        type: Sequelize.DOUBLE
      },
      start_location_id: {
        type: Sequelize.BIGINT
      },
      title: {
        type: Sequelize.STRING
      },
      type: {
        allowNull: false,
        type: Sequelize.STRING
      },
      volume: {
        type: Sequelize.DOUBLE
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable('Contracts');
  }
};

Solution

  • We recently encountered the same issue, the fix was to add the following option to our environment config in the config.json:

    dialectOptions: {
        ssl: true
    }
    

    When the sequelize cli attempts to validate the schema of the SequelizeMeta table it runs a sequence of queries - one of these was timing out after about half an hour when run without the above option.

    Note: Our first migration run was still working as it was creating the table and so skipped the validation.