-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4787 from bcgov/feat/4771
feat(4771): add data migration for Webhook URL duplication
- Loading branch information
Showing
5 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
data-migrations/migrations/20250127191932-ag_ministry_webhook_duplicate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export const up = async (db, client) => { | ||
const session = client.startSession(); | ||
|
||
await session.withTransaction(async () => { | ||
const PrivateCloudProductWebhook = db.collection('PrivateCloudProductWebhook'); | ||
const PrivateCloudProject = db.collection('PrivateCloudProject'); | ||
|
||
const baseWebhook = await PrivateCloudProductWebhook.findOne({ licencePlate: { $eq: 'e5ced5' } }); | ||
if (!baseWebhook) return; | ||
|
||
const targetProducts = await PrivateCloudProject.find({ | ||
ministry: { $in: ['AG', 'PSSG', 'EMBC'] }, | ||
status: { $eq: 'ACTIVE' }, | ||
}) | ||
.project({ licencePlate: 1 }) | ||
.toArray(); | ||
|
||
const webhookDocsToCopy = targetProducts.map(({ licencePlate }) => { | ||
return { | ||
licencePlate, | ||
url: baseWebhook.url, | ||
secret: baseWebhook.secret ?? '', | ||
username: baseWebhook.username ?? '', | ||
password: baseWebhook.password ?? '', | ||
}; | ||
}); | ||
|
||
if (webhookDocsToCopy.length === 0) return; | ||
|
||
const targetLicensePlates = targetProducts.map(({ licencePlate }) => licencePlate); | ||
await PrivateCloudProductWebhook.deleteMany({ licencePlate: { $in: targetLicensePlates } }); | ||
|
||
const result = await PrivateCloudProductWebhook.insertMany(webhookDocsToCopy, {}); | ||
console.log('renamag_ministry_webhook_duplicate:', result); | ||
}); | ||
|
||
session.endSession(); | ||
}; | ||
|
||
export const down = async (db, client) => {}; |