I added a new column to my old table in postgresql database using migrations and assigned default value for that column.
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
return Promise.all([
queryInterface.addColumn(
'notifications', // table name
'flag', // new field name
{
type: Sequelize.INTEGER,
defaultValue: 0,
allowNull: false,
},
),
]);
},
down: async (queryInterface, Sequelize) => {
}
};
Now i want to change to specific values of that column. How can i do that with hooks or service? I am new at node.js, i will really appreciate your help.
My notifications.model.js
const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;
module.exports = function (app) {
const sequelizeClient = app.get('sequelizeClient');
const notifications = sequelizeClient.define('notifications', {
senderId: {
type: DataTypes.INTEGER,
allowNull: false
},
recipientId: {
type: DataTypes.INTEGER,
allowNull: false
},
notificationtype: {
type: DataTypes.STRING,
allowNull: false
},
postId:{
type:DataTypes.INTEGER,
allowNull:true
},
conversationId:{
type:DataTypes.INTEGER,
allowNull:true
}
},
);
return notifications;
};
This is my notifications.hooks.js. What should i add to update the flag to 1?
const { authenticate } = require('@feathersjs/authentication').hooks;
const authHooks = require('feathers-authentication-hooks');
const { fastJoin, discard, disallow } = require('feathers-hooks-common');
const acquireNotification = require('../../hooks/notifications/acquire_notification');
const relateWithUser = require('../../hooks/notifications/relate_with_users');
const reverse = require('../../hooks/common/reverse');
module.exports = {
before: {
all: [
authenticate('jwt'),
reverse(),
],
find: [
acquireNotification(),
reverse()
],
get: [
acquireNotification()
],
create: [
authHooks.associateCurrentUser({
idField: 'id',
as: 'senderId'
}),
],
update: [
],
patch: [
],
remove: [
]
},
after: {
all: [],
find: [
fastJoin(relateWithUser),
],
get: [],
create: [
fastJoin(relateWithUser),
],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};
flagfield value for those records to a specified value?