From 87ac376b467763b9cfdc592f5e31ddad998da0bd Mon Sep 17 00:00:00 2001 From: adithya_dinesh Date: Mon, 25 Nov 2024 12:23:50 +0530 Subject: [PATCH 1/8] rollout db changes --- ...091243-alter-resource-add-assoc-res-ids.js | 17 ++++ .../20241122100559-create-table-rollouts.js | 89 +++++++++++++++++++ src/distributionColumns.psql | 3 +- 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/database/migrations/20241122091243-alter-resource-add-assoc-res-ids.js create mode 100644 src/database/migrations/20241122100559-create-table-rollouts.js diff --git a/src/database/migrations/20241122091243-alter-resource-add-assoc-res-ids.js b/src/database/migrations/20241122091243-alter-resource-add-assoc-res-ids.js new file mode 100644 index 00000000..691b940c --- /dev/null +++ b/src/database/migrations/20241122091243-alter-resource-add-assoc-res-ids.js @@ -0,0 +1,17 @@ +'use strict' + +module.exports = { + up: async (queryInterface, Sequelize) => { + // Add the `associated_resource_ids` column to the `resources` table + await queryInterface.addColumn('resources', 'associated_resource_ids', { + type: Sequelize.ARRAY(Sequelize.INTEGER), + allowNull: false, + defaultValue: [], + }) + }, + + down: async (queryInterface, Sequelize) => { + // Remove the `associated_resource_ids` column from the `resources` table + await queryInterface.removeColumn('resources', 'associated_resource_ids') + }, +} diff --git a/src/database/migrations/20241122100559-create-table-rollouts.js b/src/database/migrations/20241122100559-create-table-rollouts.js new file mode 100644 index 00000000..623ef35f --- /dev/null +++ b/src/database/migrations/20241122100559-create-table-rollouts.js @@ -0,0 +1,89 @@ +'use strict' + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.createTable('rollouts', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER, + }, + resource_type: { + allowNull: false, + unique: true, + type: Sequelize.STRING, + }, + resource_id: { + allowNull: false, + type: Sequelize.STRING, + }, + status: { + allowNull: false, + type: Sequelize.ENUM('PENDING', 'ROLLED_OUT', 'INACTIVE'), + defaultValue: 'PENDING', + }, + rollout_date: { + allowNull: false, + type: Sequelize.DATE, + }, + organization_id: { + primaryKey: true, + allowNull: false, + type: Sequelize.STRING, + }, + user_id: { + allowNull: false, + type: Sequelize.STRING, + }, + start_date: { + allowNull: false, + type: Sequelize.DATE, + }, + end_date: { + allowNull: false, + type: Sequelize.DATE, + }, + published_id: { + type: Sequelize.STRING, + }, + title: { + allowNull: false, + type: Sequelize.STRING, + }, + blob_path: { + allowNull: true, + type: Sequelize.STRING, + }, + parent_id: { + allowNull: false, + defaultValue: 0, + type: Sequelize.INTEGER, + }, + type: { + allowNull: false, + type: Sequelize.ENUM('PROGRAM', 'SOLUTION'), + type: Sequelize.STRING, + }, + duplicate_template_id: { + type: Sequelize.STRING, + }, + created_at: { + allowNull: false, + type: Sequelize.DATE, + }, + updated_at: { + allowNull: false, + type: Sequelize.DATE, + }, + deleted_at: { + type: Sequelize.DATE, + }, + }) + }, + + async down(queryInterface, Sequelize) { + await queryInterface.dropTable('rollouts') + }, +} diff --git a/src/distributionColumns.psql b/src/distributionColumns.psql index db3adc11..3be7ca2e 100644 --- a/src/distributionColumns.psql +++ b/src/distributionColumns.psql @@ -10,4 +10,5 @@ SELECT create_distributed_table('resource_creator_mapping', 'creator_id'); SELECT create_distributed_table('review_resources', 'reviewer_id'); SELECT create_distributed_table('review_stages', 'organization_id'); SELECT create_distributed_table('reviews', 'organization_id'); -SELECT create_distributed_table('activities', 'object_id'); \ No newline at end of file +SELECT create_distributed_table('activities', 'object_id'); +SELECT create_distributed_table('rollouts', 'organization_id'); \ No newline at end of file From 8e6fc5553654da2ca596ab22d3d68443f5b16d02 Mon Sep 17 00:00:00 2001 From: adithya_dinesh Date: Mon, 25 Nov 2024 12:39:39 +0530 Subject: [PATCH 2/8] rollout db changes --- .../20241122100559-create-table-rollouts.js | 8 ++ src/database/models/resources.js | 4 + src/database/models/rollouts.js | 117 ++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 src/database/models/rollouts.js diff --git a/src/database/migrations/20241122100559-create-table-rollouts.js b/src/database/migrations/20241122100559-create-table-rollouts.js index 623ef35f..20c20d1e 100644 --- a/src/database/migrations/20241122100559-create-table-rollouts.js +++ b/src/database/migrations/20241122100559-create-table-rollouts.js @@ -69,6 +69,14 @@ module.exports = { duplicate_template_id: { type: Sequelize.STRING, }, + created_by: { + allowNull: false, + type: Sequelize.STRING, + }, + updated_by: { + allowNull: false, + type: Sequelize.STRING, + }, created_at: { allowNull: false, type: Sequelize.DATE, diff --git a/src/database/models/resources.js b/src/database/models/resources.js index 60d36cf9..c24c337d 100644 --- a/src/database/models/resources.js +++ b/src/database/models/resources.js @@ -90,6 +90,10 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.BOOLEAN, defaultValue: false, }, + associated_resource_ids: { + type: DataTypes.ARRAY(DataTypes.INTEGER), + defaultValue: [], + }, }, { modelName: 'Resource', diff --git a/src/database/models/rollouts.js b/src/database/models/rollouts.js new file mode 100644 index 00000000..3fd91266 --- /dev/null +++ b/src/database/models/rollouts.js @@ -0,0 +1,117 @@ +const common = require('@constants/common') + +module.exports = (sequelize, DataTypes) => { + const Rollouts = sequelize.define( + 'Rollouts', + { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: DataTypes.INTEGER, + }, + resource_type: { + allowNull: false, + type: DataTypes.STRING, + }, + resource_id: { + type: DataTypes.INTEGER, + }, + status: { + allowNull: false, + type: DataTypes.ENUM('PENDING', 'ROLLED_OUT', 'INACTIVE'), + defaultValue: 'PENDING', + }, + rollout_date: { + allowNull: true, + type: DataTypes.STRING, + }, + organization_id: { + primaryKey: true, + allowNull: false, + type: DataTypes.STRING, + }, + user_id: { + allowNull: false, + type: DataTypes.STRING, + }, + start_date: { + allowNull: true, + type: DataTypes.STRING, + }, + end_date: { + allowNull: true, + type: DataTypes.STRING, + }, + published_id: { + type: DataTypes.STRING, + }, + title: { + allowNull: false, + type: DataTypes.STRING, + }, + blob_path: { + allowNull: true, + type: DataTypes.STRING, + }, + parent_id: { + type: DataTypes.INTEGER, + }, + stage: { + allowNull: true, + type: DataTypes.ENUM('PROGRAM', 'SOLUTION'), + }, + duplicate_template_id: { + type: DataTypes.STRING, + }, + created_by: { + allowNull: false, + type: DataTypes.STRING, + }, + updated_by: { + type: DataTypes.STRING, + }, + created_at: { + allowNull: true, + type: DataTypes.STRING, + }, + updated_at: { + allowNull: true, + type: DataTypes.STRING, + }, + deleted_at: { + allowNull: true, + type: DataTypes.STRING, + }, + }, + { + modelName: 'Rollouts', + tableName: 'rollouts', + freezeTableName: true, + paranoid: true, + } + ) + // Helper function to emit user actions with dynamic action types + const emitUserAction = async (instance, actionType) => { + try { + if (actionType) { + eventEmitter.emit(common.EVENT_ADD_USER_ACTION, { + actionCode: common.USER_ACTIONS[instance.type][actionType], + userId: instance.user_id, + objectId: instance.id, + objectType: common.MODEL_NAMES.RESOURCE, + orgId: instance.organization_id, + }) + } + } catch (error) { + console.error(`Error during ${actionType} hook:`, error) + throw error + } + } + + Rollouts.addHook('afterCreate', (instance) => emitUserAction(instance, 'ROLLOUT_CREATED')) + + Rollouts.addHook('afterDestroy', (instance) => emitUserAction(instance, 'ROLLOUT_DELETED')) + + return Rollouts +} From da94e45f54f721955cc1ad3cf40acbbbf3d4ea74 Mon Sep 17 00:00:00 2001 From: adithya_dinesh Date: Mon, 25 Nov 2024 18:48:29 +0530 Subject: [PATCH 3/8] review comments --- src/constants/common.js | 3 ++ ...091243-alter-resource-add-assoc-res-ids.js | 17 ------ .../20241122100559-create-table-rollouts.js | 12 ++++- .../20241125122503-add-activites-rollout.js | 54 +++++++++++++++++++ src/database/models/resources.js | 4 -- src/database/models/rollouts.js | 33 ++++-------- 6 files changed, 79 insertions(+), 44 deletions(-) delete mode 100644 src/database/migrations/20241122091243-alter-resource-add-assoc-res-ids.js create mode 100644 src/database/migrations/20241125122503-add-activites-rollout.js diff --git a/src/constants/common.js b/src/constants/common.js index 9a5e4fbc..59f9b77d 100644 --- a/src/constants/common.js +++ b/src/constants/common.js @@ -168,9 +168,12 @@ module.exports = { }, MODEL_NAMES: { RESOURCE: 'Resource', + ROLLOUT: 'Rollouts', }, USER_ACTIONS: { project: getResourceActions('PROJECT'), + rollout_program: getResourceActions('PROGRAM_ROLLOUT'), + rollout_solution: getResourceActions('SOLUTION_ROLLOUT'), }, EVENT_ADD_USER_ACTION: 'addUserAction', REQUEST_TIMEOUT_MS: 3000, diff --git a/src/database/migrations/20241122091243-alter-resource-add-assoc-res-ids.js b/src/database/migrations/20241122091243-alter-resource-add-assoc-res-ids.js deleted file mode 100644 index 691b940c..00000000 --- a/src/database/migrations/20241122091243-alter-resource-add-assoc-res-ids.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict' - -module.exports = { - up: async (queryInterface, Sequelize) => { - // Add the `associated_resource_ids` column to the `resources` table - await queryInterface.addColumn('resources', 'associated_resource_ids', { - type: Sequelize.ARRAY(Sequelize.INTEGER), - allowNull: false, - defaultValue: [], - }) - }, - - down: async (queryInterface, Sequelize) => { - // Remove the `associated_resource_ids` column from the `resources` table - await queryInterface.removeColumn('resources', 'associated_resource_ids') - }, -} diff --git a/src/database/migrations/20241122100559-create-table-rollouts.js b/src/database/migrations/20241122100559-create-table-rollouts.js index 20c20d1e..d1119a39 100644 --- a/src/database/migrations/20241122100559-create-table-rollouts.js +++ b/src/database/migrations/20241122100559-create-table-rollouts.js @@ -17,7 +17,7 @@ module.exports = { }, resource_id: { allowNull: false, - type: Sequelize.STRING, + type: Sequelize.INTEGER, }, status: { allowNull: false, @@ -89,6 +89,16 @@ module.exports = { type: Sequelize.DATE, }, }) + + await queryInterface.addIndex('rollouts', ['status'], { + name: 'rollouts_status_index', + }) + await queryInterface.addIndex('rollouts', ['resource_type'], { + name: 'rollouts_resource_type_index', + }) + await queryInterface.addIndex('rollouts', ['user_id'], { + name: 'rollouts_user_id_index', + }) }, async down(queryInterface, Sequelize) { diff --git a/src/database/migrations/20241125122503-add-activites-rollout.js b/src/database/migrations/20241125122503-add-activites-rollout.js new file mode 100644 index 00000000..5318ff2e --- /dev/null +++ b/src/database/migrations/20241125122503-add-activites-rollout.js @@ -0,0 +1,54 @@ +'use strict' + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + up: async (queryInterface, Sequelize) => { + const actionsData = [ + { + code: 'CREATE_PROGRAM_ROLLOUT', + description: 'created the Program rollout with', + }, + { + code: 'CREATE_SOLUTION_ROLLOUT', + description: 'created the Solution rollout with', + }, + { + code: 'DELETE_PROGRAM_ROLLOUT', + description: 'deleted the Program rollout with', + }, + { + code: 'DELETE_SOLUTION_ROLLOUT', + description: 'deleted the Solution rollout with', + }, + ] + + const actionsFinalArray = actionsData.map((action) => { + const timestamp = new Date() + return { + ...action, + created_at: timestamp, + updated_at: timestamp, + } + }) + + // Insert the data into the 'actions' table + await queryInterface.bulkInsert('actions', actionsFinalArray) + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.bulkDelete( + 'actions', + { + code: { + [Sequelize.Op.in]: [ + 'CREATE_PROGRAM_ROLLOUT', + 'CREATE_SOLUTION_ROLLOUT', + 'DELETE_PROGRAM_ROLLOUT', + 'DELETE_SOLUTION_ROLLOUT', + ], + }, + }, + {} + ) + }, +} diff --git a/src/database/models/resources.js b/src/database/models/resources.js index c24c337d..60d36cf9 100644 --- a/src/database/models/resources.js +++ b/src/database/models/resources.js @@ -90,10 +90,6 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.BOOLEAN, defaultValue: false, }, - associated_resource_ids: { - type: DataTypes.ARRAY(DataTypes.INTEGER), - defaultValue: [], - }, }, { modelName: 'Resource', diff --git a/src/database/models/rollouts.js b/src/database/models/rollouts.js index 3fd91266..fc414225 100644 --- a/src/database/models/rollouts.js +++ b/src/database/models/rollouts.js @@ -15,6 +15,7 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.STRING, }, resource_id: { + allowNull: false, type: DataTypes.INTEGER, }, status: { @@ -24,7 +25,7 @@ module.exports = (sequelize, DataTypes) => { }, rollout_date: { allowNull: true, - type: DataTypes.STRING, + type: DataTypes.DATE, }, organization_id: { primaryKey: true, @@ -36,12 +37,12 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.STRING, }, start_date: { - allowNull: true, - type: DataTypes.STRING, + allowNull: false, + type: DataTypes.DATE, }, end_date: { - allowNull: true, - type: DataTypes.STRING, + allowNull: false, + type: DataTypes.DATE, }, published_id: { type: DataTypes.STRING, @@ -57,7 +58,7 @@ module.exports = (sequelize, DataTypes) => { parent_id: { type: DataTypes.INTEGER, }, - stage: { + type: { allowNull: true, type: DataTypes.ENUM('PROGRAM', 'SOLUTION'), }, @@ -71,18 +72,6 @@ module.exports = (sequelize, DataTypes) => { updated_by: { type: DataTypes.STRING, }, - created_at: { - allowNull: true, - type: DataTypes.STRING, - }, - updated_at: { - allowNull: true, - type: DataTypes.STRING, - }, - deleted_at: { - allowNull: true, - type: DataTypes.STRING, - }, }, { modelName: 'Rollouts', @@ -96,10 +85,10 @@ module.exports = (sequelize, DataTypes) => { try { if (actionType) { eventEmitter.emit(common.EVENT_ADD_USER_ACTION, { - actionCode: common.USER_ACTIONS[instance.type][actionType], + actionCode: common.USER_ACTIONS['rollout_' + instance.resource_type.toLowerCase()][actionType], userId: instance.user_id, objectId: instance.id, - objectType: common.MODEL_NAMES.RESOURCE, + objectType: common.MODEL_NAMES.ROLLOUT, orgId: instance.organization_id, }) } @@ -109,9 +98,9 @@ module.exports = (sequelize, DataTypes) => { } } - Rollouts.addHook('afterCreate', (instance) => emitUserAction(instance, 'ROLLOUT_CREATED')) + Rollouts.addHook('afterCreate', (instance) => emitUserAction(instance, 'RESOURCE_CREATED')) - Rollouts.addHook('afterDestroy', (instance) => emitUserAction(instance, 'ROLLOUT_DELETED')) + Rollouts.addHook('afterDestroy', (instance) => emitUserAction(instance, 'RESOURCE_DELETED')) return Rollouts } From f3e7a19b6cc3cfe03185550ba66990c5bfbb810b Mon Sep 17 00:00:00 2001 From: adithya_dinesh Date: Tue, 26 Nov 2024 12:38:24 +0530 Subject: [PATCH 4/8] review comments --- src/constants/common.js | 1 + .../migrations/20241125122503-add-activites-rollout.js | 10 ++++++++++ src/database/models/rollouts.js | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/src/constants/common.js b/src/constants/common.js index 59f9b77d..c8d09340 100644 --- a/src/constants/common.js +++ b/src/constants/common.js @@ -198,4 +198,5 @@ module.exports = { RECOMMENDED_DURATION: 'recommended_duration', NUMBER: 'number', STRING: 'string', + ROLLOUT_STATUS_PUBLISHED: 'PUBLISHED', } diff --git a/src/database/migrations/20241125122503-add-activites-rollout.js b/src/database/migrations/20241125122503-add-activites-rollout.js index 5318ff2e..d1d0cd4b 100644 --- a/src/database/migrations/20241125122503-add-activites-rollout.js +++ b/src/database/migrations/20241125122503-add-activites-rollout.js @@ -20,6 +20,14 @@ module.exports = { code: 'DELETE_SOLUTION_ROLLOUT', description: 'deleted the Solution rollout with', }, + { + code: 'PROGRAM_ROLLOUT_PUBLISHED', + description: 'published the Program rollout with', + }, + { + code: 'SOLUTION_ROLLOUT_PUBLISHED', + description: 'published the Solution rollout with', + }, ] const actionsFinalArray = actionsData.map((action) => { @@ -45,6 +53,8 @@ module.exports = { 'CREATE_SOLUTION_ROLLOUT', 'DELETE_PROGRAM_ROLLOUT', 'DELETE_SOLUTION_ROLLOUT', + 'PROGRAM_ROLLOUT_PUBLISHED', + 'SOLUTION_ROLLOUT_PUBLISHED', ], }, }, diff --git a/src/database/models/rollouts.js b/src/database/models/rollouts.js index fc414225..394e2ca4 100644 --- a/src/database/models/rollouts.js +++ b/src/database/models/rollouts.js @@ -102,5 +102,11 @@ module.exports = (sequelize, DataTypes) => { Rollouts.addHook('afterDestroy', (instance) => emitUserAction(instance, 'RESOURCE_DELETED')) + Rollouts.addHook('afterUpdate', (instance) => { + if (instance.status == common.ROLLOUT_STATUS_PUBLISHED) { + emitUserAction(instance, 'RESOURCE_PUBLISHED') + } + }) + return Rollouts } From b123e3663a4815a4e7ad1638dde7c1653fadd0d4 Mon Sep 17 00:00:00 2001 From: adithya_dinesh Date: Wed, 27 Nov 2024 18:27:54 +0530 Subject: [PATCH 5/8] review comments --- .../migrations/20241122100559-create-table-rollouts.js | 3 +-- src/database/models/rollouts.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/database/migrations/20241122100559-create-table-rollouts.js b/src/database/migrations/20241122100559-create-table-rollouts.js index d1119a39..fef65e87 100644 --- a/src/database/migrations/20241122100559-create-table-rollouts.js +++ b/src/database/migrations/20241122100559-create-table-rollouts.js @@ -25,7 +25,7 @@ module.exports = { defaultValue: 'PENDING', }, rollout_date: { - allowNull: false, + allowNull: true, type: Sequelize.DATE, }, organization_id: { @@ -64,7 +64,6 @@ module.exports = { type: { allowNull: false, type: Sequelize.ENUM('PROGRAM', 'SOLUTION'), - type: Sequelize.STRING, }, duplicate_template_id: { type: Sequelize.STRING, diff --git a/src/database/models/rollouts.js b/src/database/models/rollouts.js index 394e2ca4..602cadd2 100644 --- a/src/database/models/rollouts.js +++ b/src/database/models/rollouts.js @@ -2,7 +2,7 @@ const common = require('@constants/common') module.exports = (sequelize, DataTypes) => { const Rollouts = sequelize.define( - 'Rollouts', + 'Rollout', { id: { allowNull: false, @@ -74,7 +74,7 @@ module.exports = (sequelize, DataTypes) => { }, }, { - modelName: 'Rollouts', + modelName: 'Rollout', tableName: 'rollouts', freezeTableName: true, paranoid: true, From f3c68aebd53b6e0d44fbe0f525b38ed295649040 Mon Sep 17 00:00:00 2001 From: adithya_dinesh Date: Wed, 27 Nov 2024 19:24:13 +0530 Subject: [PATCH 6/8] review changes --- src/constants/common.js | 3 +++ .../20241122100559-create-table-rollouts.js | 7 ++----- src/database/models/rollouts.js | 20 +++++++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/constants/common.js b/src/constants/common.js index e6b09336..d47d829d 100644 --- a/src/constants/common.js +++ b/src/constants/common.js @@ -21,6 +21,9 @@ function getResourceActions(resource) { RESOURCE_REPORTED: `${resource}_REJECTED_AND_REPORTED`, RESOURCE_REJECTED: `${resource}_REJECTED`, REVIEW_INPROGRESS: `${resource}_REVIEW_INPROGRESS`, + ROLLOUT_CREATED: `CREATE_${resource}`, + ROLLOUT_DELETED: `DELETE_${resource}`, + ROLLOUT_PUBLISHED: `${resource}_PUBLISHED`, } } diff --git a/src/database/migrations/20241122100559-create-table-rollouts.js b/src/database/migrations/20241122100559-create-table-rollouts.js index fef65e87..d94ee8f2 100644 --- a/src/database/migrations/20241122100559-create-table-rollouts.js +++ b/src/database/migrations/20241122100559-create-table-rollouts.js @@ -12,7 +12,6 @@ module.exports = { }, resource_type: { allowNull: false, - unique: true, type: Sequelize.STRING, }, resource_id: { @@ -63,7 +62,8 @@ module.exports = { }, type: { allowNull: false, - type: Sequelize.ENUM('PROGRAM', 'SOLUTION'), + type: Sequelize.ENUM('program', 'solution'), + defaultValue: 'program', }, duplicate_template_id: { type: Sequelize.STRING, @@ -92,9 +92,6 @@ module.exports = { await queryInterface.addIndex('rollouts', ['status'], { name: 'rollouts_status_index', }) - await queryInterface.addIndex('rollouts', ['resource_type'], { - name: 'rollouts_resource_type_index', - }) await queryInterface.addIndex('rollouts', ['user_id'], { name: 'rollouts_user_id_index', }) diff --git a/src/database/models/rollouts.js b/src/database/models/rollouts.js index 602cadd2..0d7e8b1a 100644 --- a/src/database/models/rollouts.js +++ b/src/database/models/rollouts.js @@ -1,7 +1,7 @@ const common = require('@constants/common') module.exports = (sequelize, DataTypes) => { - const Rollouts = sequelize.define( + const Rollout = sequelize.define( 'Rollout', { id: { @@ -60,7 +60,7 @@ module.exports = (sequelize, DataTypes) => { }, type: { allowNull: true, - type: DataTypes.ENUM('PROGRAM', 'SOLUTION'), + type: DataTypes.ENUM('program', 'solution'), }, duplicate_template_id: { type: DataTypes.STRING, @@ -82,10 +82,14 @@ module.exports = (sequelize, DataTypes) => { ) // Helper function to emit user actions with dynamic action types const emitUserAction = async (instance, actionType) => { + console.log(actionType, 'actionType') + // CREATE_PROGRAM_ROLLOUT + // rollout_program + // console.log(common.USER_ACTIONS['rollout_' + instance.resource_type.toLowerCase()][actionType], 'jjj') try { if (actionType) { eventEmitter.emit(common.EVENT_ADD_USER_ACTION, { - actionCode: common.USER_ACTIONS['rollout_' + instance.resource_type.toLowerCase()][actionType], + actionCode: common.USER_ACTIONS['rollout_' + instance.type.toLowerCase()][actionType], userId: instance.user_id, objectId: instance.id, objectType: common.MODEL_NAMES.ROLLOUT, @@ -98,15 +102,15 @@ module.exports = (sequelize, DataTypes) => { } } - Rollouts.addHook('afterCreate', (instance) => emitUserAction(instance, 'RESOURCE_CREATED')) + Rollout.addHook('afterCreate', (instance) => emitUserAction(instance, `ROLLOUT_CREATE`)) - Rollouts.addHook('afterDestroy', (instance) => emitUserAction(instance, 'RESOURCE_DELETED')) + Rollout.addHook('afterDestroy', (instance) => emitUserAction(instance, 'ROLLOUT_DELETED')) - Rollouts.addHook('afterUpdate', (instance) => { + Rollout.addHook('afterUpdate', (instance) => { if (instance.status == common.ROLLOUT_STATUS_PUBLISHED) { - emitUserAction(instance, 'RESOURCE_PUBLISHED') + emitUserAction(instance, 'ROLLOUT_PUBLISHED') } }) - return Rollouts + return Rollout } From 1c8c92a9452def4a9d61fa0bf908534115b65aca Mon Sep 17 00:00:00 2001 From: adithya_dinesh Date: Thu, 28 Nov 2024 16:58:08 +0530 Subject: [PATCH 7/8] review comments --- .../migrations/20241122100559-create-table-rollouts.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/database/migrations/20241122100559-create-table-rollouts.js b/src/database/migrations/20241122100559-create-table-rollouts.js index d94ee8f2..64fb1a0e 100644 --- a/src/database/migrations/20241122100559-create-table-rollouts.js +++ b/src/database/migrations/20241122100559-create-table-rollouts.js @@ -95,6 +95,9 @@ module.exports = { await queryInterface.addIndex('rollouts', ['user_id'], { name: 'rollouts_user_id_index', }) + await queryInterface.addIndex('rollouts', ['title'], { + name: 'rollouts_title_index', + }) }, async down(queryInterface, Sequelize) { From d64d2f3c1a4300e17e200a337ea900c8488c0be3 Mon Sep 17 00:00:00 2001 From: adithya_dinesh Date: Thu, 28 Nov 2024 18:55:44 +0530 Subject: [PATCH 8/8] review comments --- .../migrations/20241122100559-create-table-rollouts.js | 4 ++-- src/database/models/rollouts.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/database/migrations/20241122100559-create-table-rollouts.js b/src/database/migrations/20241122100559-create-table-rollouts.js index 64fb1a0e..63eac835 100644 --- a/src/database/migrations/20241122100559-create-table-rollouts.js +++ b/src/database/migrations/20241122100559-create-table-rollouts.js @@ -23,7 +23,7 @@ module.exports = { type: Sequelize.ENUM('PENDING', 'ROLLED_OUT', 'INACTIVE'), defaultValue: 'PENDING', }, - rollout_date: { + published_on: { allowNull: true, type: Sequelize.DATE, }, @@ -65,7 +65,7 @@ module.exports = { type: Sequelize.ENUM('program', 'solution'), defaultValue: 'program', }, - duplicate_template_id: { + template_id: { type: Sequelize.STRING, }, created_by: { diff --git a/src/database/models/rollouts.js b/src/database/models/rollouts.js index 0d7e8b1a..59951b5f 100644 --- a/src/database/models/rollouts.js +++ b/src/database/models/rollouts.js @@ -23,7 +23,7 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.ENUM('PENDING', 'ROLLED_OUT', 'INACTIVE'), defaultValue: 'PENDING', }, - rollout_date: { + published_on: { allowNull: true, type: DataTypes.DATE, }, @@ -62,7 +62,7 @@ module.exports = (sequelize, DataTypes) => { allowNull: true, type: DataTypes.ENUM('program', 'solution'), }, - duplicate_template_id: { + template_id: { type: DataTypes.STRING, }, created_by: {