Skip to content

Commit

Permalink
Change onDelete behavior to SET NULL for foreign key in StatusPage mo…
Browse files Browse the repository at this point in the history
…del and add migration for the update
  • Loading branch information
simlarsen committed Sep 23, 2024
1 parent e6bc276 commit d6530cb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Common/Models/DatabaseModels/StatusPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ export default class StatusPage extends BaseModel {
{
eager: false,
nullable: true,
onDelete: "CASCADE",
onDelete: "SET NULL",
orphanedRowAction: "nullify",
},
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MigrationName1727104469670 implements MigrationInterface {
public name = 'MigrationName1727104469670'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "StatusPage" DROP CONSTRAINT "FK_4e347d3f99b67dacd149beaf61d"`);
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(`ALTER TABLE "StatusPage" ADD CONSTRAINT "FK_4e347d3f99b67dacd149beaf61d" FOREIGN KEY ("callSmsConfigId") REFERENCES "ProjectCallSMSConfig"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "StatusPage" DROP CONSTRAINT "FK_4e347d3f99b67dacd149beaf61d"`);
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 "StatusPage" ADD CONSTRAINT "FK_4e347d3f99b67dacd149beaf61d" FOREIGN KEY ("callSmsConfigId") REFERENCES "ProjectCallSMSConfig"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { MigrationName1727101782315 } from "./1727101782315-MigrationName";
import { MigrationName1727102156072 } from "./1727102156072-MigrationName";
import { MigrationName1727102331367 } from "./1727102331367-MigrationName";
import { MigrationName1727103023745 } from "./1727103023745-MigrationName";
import { MigrationName1727104469670 } from "./1727104469670-MigrationName";

export default [
InitialMigration,
Expand Down Expand Up @@ -134,4 +135,5 @@ export default [
MigrationName1727102156072,
MigrationName1727102331367,
MigrationName1727103023745,
MigrationName1727104469670
];

0 comments on commit d6530cb

Please sign in to comment.