Skip to content

Commit

Permalink
Merge pull request #4787 from bcgov/feat/4771
Browse files Browse the repository at this point in the history
feat(4771): add data migration for Webhook URL duplication
  • Loading branch information
junminahn authored Jan 28, 2025
2 parents 31d34b6 + 936dd37 commit 226667f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ jobs:
deploy:
needs: [build-push-app, build-push-pre-prisma, build-push-pre-data-migrations, build-push-email, build-push-m365proxy, build-push-nats-provision]
runs-on: ubuntu-22.04
timeout-minutes: 5
timeout-minutes: 10
permissions:
contents: read
environment:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
jobs:
deploy:
runs-on: ubuntu-22.04
timeout-minutes: 5
timeout-minutes: 10
permissions:
contents: read
environment:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:
jobs:
deploy:
runs-on: ubuntu-22.04
timeout-minutes: 5
timeout-minutes: 10
permissions:
contents: read
environment:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
deploy:
needs: [set-tag, build-push-app, build-push-pre-prisma, build-push-pre-data-migrations, build-push-email]
runs-on: ubuntu-22.04
timeout-minutes: 5
timeout-minutes: 10
permissions:
contents: read
environment:
Expand Down
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) => {};

0 comments on commit 226667f

Please sign in to comment.