Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(db): nullify fields for soft-deleted records #1023

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

module.exports = {
async up(queryInterface, Sequelize) {
// Update fields to NULL where deleted_at is not NULL
await queryInterface.sequelize.query(`
UPDATE "user_extensions"
SET
"custom_entity_text" = NULL,
"name" = NULL,
"email" = NULL,
"phone" = NULL,
WHERE "deleted_at" IS NOT NULL;
`)
},

async down(queryInterface, Sequelize) {
// Reverting this update is unnecessary as it's a corrective action
},
}
6 changes: 6 additions & 0 deletions src/database/queries/mentorExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module.exports = class MentorExtensionQueries {
throw error
}
}

static async removeMentorDetails(userId) {
try {
return await MentorExtension.update(
Expand All @@ -125,6 +126,10 @@ module.exports = class MentorExtensionQueries {
visible_to_organizations: [],
external_session_visibility: null,
external_mentor_visibility: null,
custom_entity_text: null,
name: null,
email: null,
phone: null,
deleted_at: Date.now(),
},
{
Expand All @@ -138,6 +143,7 @@ module.exports = class MentorExtensionQueries {
throw error
}
}

static async getMentorsByUserIds(ids, options = {}, unscoped = false) {
try {
const query = {
Expand Down
5 changes: 5 additions & 0 deletions src/database/queries/userExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ module.exports = class MenteeExtensionQueries {
throw error
}
}

static async removeMenteeDetails(userId) {
try {
return await MenteeExtension.update(
Expand All @@ -195,6 +196,10 @@ module.exports = class MenteeExtensionQueries {
external_mentor_visibility: null,
external_mentee_visibility: null,
mentee_visibility: null,
custom_entity_text: null,
name: null,
email: null,
phone: null,
deleted_at: Date.now(),
},
{
Expand Down