Sequalizejs adding paranoid configuration to an existing table
I added the deletedAt field using migration like this:
"use strict";
module.exports = {
up: function(migration, DataTypes, done) {
// add altering commands here, calling 'done' when finished
migration.addColumn(
'mytablename',
'deletedAt',
{
type: DataTypes.DATE,
allowNull: true,
validate: {
}
}
);
done();
},
down: function(migration, DataTypes, done) {
// add reverting commands here, calling 'done' when finished
migration.removeColumn('mytablename', 'deletedAt');
done();
}
};
And added the configuration:
paranoid: true,
to my model
It seems to work.
Does anyone have a better solution?
Small update.
According to the sequelize
version 6.4.0
(what I am currently using), the migration looks like this:
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn(
'TABLE_NAME',
'deletedAt',
{
allowNull: true,
type: Sequelize.DATE
})
},
down: (queryInterface, Sequelize) => {
return queryInterface.removeColumn('TABLE_NAME', 'deletedAt')
}
};
I mean that the done
method is not required.