feat: add triggeredByAlertEpisodeId to on-call related tables and update UserOnCallLogService comments

This commit is contained in:
Nawaz Dhandala
2026-01-26 23:35:05 +00:00
parent 9dabce1b7a
commit 214ac678d3
3 changed files with 72 additions and 30 deletions

View File

@@ -1,32 +1,71 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class MigrationName1769469813786 implements MigrationInterface {
public name = 'MigrationName1769469813786'
public name = "MigrationName1769469813786";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD "triggeredByAlertEpisodeId" uuid`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" ADD "triggeredByAlertEpisodeId" uuid`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" ADD "triggeredByAlertEpisodeId" uuid`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type":"Recurring","value":{"intervalType":"Day","intervalCount":{"_type":"PositiveNumber","value":1}}}'`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type":"RestrictionTimes","value":{"restictionType":"None","dayRestrictionTimes":null,"weeklyRestrictionTimes":[]}}'`);
await queryRunner.query(`CREATE INDEX "IDX_1fda33fffd89b95dafa537f3be" ON "OnCallDutyPolicyExecutionLogTimeline" ("triggeredByAlertEpisodeId") `);
await queryRunner.query(`CREATE INDEX "IDX_2c98f4eeddf1d00ec073b49352" ON "UserOnCallLogTimeline" ("triggeredByAlertEpisodeId") `);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD CONSTRAINT "FK_1fda33fffd89b95dafa537f3bef" FOREIGN KEY ("triggeredByAlertEpisodeId") REFERENCES "AlertEpisode"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" ADD CONSTRAINT "FK_114aa962f2bc3c6736a1469df36" FOREIGN KEY ("triggeredByAlertEpisodeId") REFERENCES "AlertEpisode"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" ADD CONSTRAINT "FK_2c98f4eeddf1d00ec073b493525" FOREIGN KEY ("triggeredByAlertEpisodeId") REFERENCES "AlertEpisode"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" DROP CONSTRAINT "FK_2c98f4eeddf1d00ec073b493525"`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" DROP CONSTRAINT "FK_114aa962f2bc3c6736a1469df36"`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP CONSTRAINT "FK_1fda33fffd89b95dafa537f3bef"`);
await queryRunner.query(`DROP INDEX "public"."IDX_2c98f4eeddf1d00ec073b49352"`);
await queryRunner.query(`DROP INDEX "public"."IDX_1fda33fffd89b95dafa537f3be"`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type": "RestrictionTimes", "value": {"restictionType": "None", "dayRestrictionTimes": null, "weeklyRestrictionTimes": []}}'`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type": "Recurring", "value": {"intervalType": "Day", "intervalCount": {"_type": "PositiveNumber", "value": 1}}}'`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" DROP COLUMN "triggeredByAlertEpisodeId"`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" DROP COLUMN "triggeredByAlertEpisodeId"`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP COLUMN "triggeredByAlertEpisodeId"`);
}
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD "triggeredByAlertEpisodeId" uuid`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" ADD "triggeredByAlertEpisodeId" uuid`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" ADD "triggeredByAlertEpisodeId" uuid`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type":"Recurring","value":{"intervalType":"Day","intervalCount":{"_type":"PositiveNumber","value":1}}}'`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type":"RestrictionTimes","value":{"restictionType":"None","dayRestrictionTimes":null,"weeklyRestrictionTimes":[]}}'`,
);
await queryRunner.query(
`CREATE INDEX "IDX_1fda33fffd89b95dafa537f3be" ON "OnCallDutyPolicyExecutionLogTimeline" ("triggeredByAlertEpisodeId") `,
);
await queryRunner.query(
`CREATE INDEX "IDX_2c98f4eeddf1d00ec073b49352" ON "UserOnCallLogTimeline" ("triggeredByAlertEpisodeId") `,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD CONSTRAINT "FK_1fda33fffd89b95dafa537f3bef" FOREIGN KEY ("triggeredByAlertEpisodeId") REFERENCES "AlertEpisode"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" ADD CONSTRAINT "FK_114aa962f2bc3c6736a1469df36" FOREIGN KEY ("triggeredByAlertEpisodeId") REFERENCES "AlertEpisode"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" ADD CONSTRAINT "FK_2c98f4eeddf1d00ec073b493525" FOREIGN KEY ("triggeredByAlertEpisodeId") REFERENCES "AlertEpisode"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" DROP CONSTRAINT "FK_2c98f4eeddf1d00ec073b493525"`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" DROP CONSTRAINT "FK_114aa962f2bc3c6736a1469df36"`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP CONSTRAINT "FK_1fda33fffd89b95dafa537f3bef"`,
);
await queryRunner.query(
`DROP INDEX "public"."IDX_2c98f4eeddf1d00ec073b49352"`,
);
await queryRunner.query(
`DROP INDEX "public"."IDX_1fda33fffd89b95dafa537f3be"`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type": "RestrictionTimes", "value": {"restictionType": "None", "dayRestrictionTimes": null, "weeklyRestrictionTimes": []}}'`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type": "Recurring", "value": {"intervalType": "Day", "intervalCount": {"_type": "PositiveNumber", "value": 1}}}'`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" DROP COLUMN "triggeredByAlertEpisodeId"`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" DROP COLUMN "triggeredByAlertEpisodeId"`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP COLUMN "triggeredByAlertEpisodeId"`,
);
}
}

View File

@@ -473,5 +473,5 @@ export default [
MigrationName1769202898645,
MigrationName1769428619414,
MigrationName1769428821686,
MigrationName1769469813786
MigrationName1769469813786,
];

View File

@@ -236,8 +236,10 @@ export class Service extends DatabaseService<Model> {
return createdItem;
}
// find immediate notification rule and alert the user.
// Determine the alertSeverityId - can come from alert or alertEpisode
/*
* find immediate notification rule and alert the user.
* Determine the alertSeverityId - can come from alert or alertEpisode
*/
const alertSeverityIdForQuery: ObjectID | undefined =
alert && alert.alertSeverityId
? (alert.alertSeverityId as ObjectID)
@@ -326,7 +328,8 @@ export class Service extends DatabaseService<Model> {
if (
userNotificationEventType === UserNotificationEventType.IncidentCreated ||
userNotificationEventType === UserNotificationEventType.AlertCreated ||
userNotificationEventType === UserNotificationEventType.AlertEpisodeCreated
userNotificationEventType ===
UserNotificationEventType.AlertEpisodeCreated
) {
notificationRuleType = NotificationRuleType.ON_CALL_EXECUTED;
} else {