I have the following migration file:
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(t => {
return queryInterface.addColumn('Vendors', 'status', Sequelize.STRING(30), { transaction: t }).then(() => {
console.log("Created column..."); // this prints
return queryInterface.addConstraint('Vendors', ['status'], {
type: 'check',
name: 'Vendors_status_check',
where: {
status: ['UNAPPROVED', 'SUBMITTED_FOR_APPROVAL', 'APPROVED', 'SUSPENDED']
},
}, { transaction: t });
}).catch(err => {
console.log("Error::", err);
});
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(t => {
// return queryInterface.removeColumn('Vendors', 'status', { transaction: t });
return queryInterface.removeConstraint('Vendors', 'Vendors_status_check', { transaction: t }).then(() => {
return queryInterface.removeColumn('Vendors', 'status', { transaction: t });
});
})
}
};
When I run sequelize-cli db:migrate
, I get the following output & then the the command just "hangs": never completes, never errors out:
Sequelize CLI [Node: 12.14.1, CLI: 5.5.1, ORM: 5.21.3]
Loaded configuration file "config\sequelize_config.js".
Using environment "development".
== 20200224080020-vendor-status: migrating =======
Created column...
If I comment out queryInterface.addConstraint
completely, the command finishes & adds the status column to the Vendors
table. Running this migration against PostgresQL, if that makes any difference.
As per sequelize db:migrate hanging I tried adding dialectOptions: {ssl: true}
to sequelize config, but there was no effect other than a deprecation warning.
Update 1
FWIW, running the following code (i.e., without a transaction) works as expected:
return queryInterface.addColumn('Vendors', 'status', {type: Sequelize.STRING(30)}/* , { transaction: t } */).then(() => {
console.log("Created column..."); // this prints
return queryInterface.addConstraint('Vendors', ['status'], {
type: 'check',
name: 'Vendors_status_check',
where: {
status: ['UNAPPROVED', 'SUBMITTED_FOR_APPROVAL', 'APPROVED', 'SUSPENDED']
},
}/* , { transaction: t } */);
}).catch(err => {
console.log("Error::", err);
});