Skip to content

Commit

Permalink
feat: refactor ScheduledMaintenanceLog model and migration for improv…
Browse files Browse the repository at this point in the history
…ed readability and structure
  • Loading branch information
simlarsen committed Jan 9, 2025
1 parent e14c54c commit 2113ffe
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 43 deletions.
38 changes: 17 additions & 21 deletions Common/Models/DatabaseModels/ScheduledMaintenanceLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ import ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";


export enum ScheduledMaintenanceLogEvent {
PublicNote = "PublicNote",
SubscriberEmailSent = "SubscriberEmailSent",
OwnerEmailSent = "OwnerEmailSent",
ScheduledMaintenanceCreated = "ScheduledMaintenanceCreated",
ScheduledMaintenanceAcknowledged = "ScheduledMaintenanceAcknowledged",
ScheduledMaintenanceResolved = "ScheduledMaintenanceResolved",
PrivateNote = "PrivateNote",
PublicNote = "PublicNote",
SubscriberEmailSent = "SubscriberEmailSent",
OwnerEmailSent = "OwnerEmailSent",
ScheduledMaintenanceCreated = "ScheduledMaintenanceCreated",
ScheduledMaintenanceAcknowledged = "ScheduledMaintenanceAcknowledged",
ScheduledMaintenanceResolved = "ScheduledMaintenanceResolved",
PrivateNote = "PrivateNote",
}

@EnableDocumentation()
Expand All @@ -46,12 +45,8 @@ export enum ScheduledMaintenanceLogEvent {
Permission.ProjectMember,
Permission.ReadScheduledMaintenanceLog,
],
delete: [

],
update: [

],
delete: [],
update: [],
})
@EnableWorkflow({
create: true,
Expand Down Expand Up @@ -158,7 +153,8 @@ export default class ScheduledMaintenanceLog extends BaseModel {
type: TableColumnType.Entity,
modelType: ScheduledMaintenance,
title: "ScheduledMaintenance",
description: "Relation to ScheduledMaintenance in which this resource belongs",
description:
"Relation to ScheduledMaintenance in which this resource belongs",
})
@ManyToOne(
() => {
Expand Down Expand Up @@ -194,7 +190,8 @@ export default class ScheduledMaintenanceLog extends BaseModel {
type: TableColumnType.ObjectID,
required: true,
title: "ScheduledMaintenance ID",
description: "Relation to ScheduledMaintenance ID in which this resource belongs",
description:
"Relation to ScheduledMaintenance ID in which this resource belongs",
})
@Column({
type: ColumnType.ObjectID,
Expand Down Expand Up @@ -313,7 +310,6 @@ export default class ScheduledMaintenanceLog extends BaseModel {
})
public deletedByUserId?: ObjectID = undefined;


@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Expand All @@ -333,7 +329,8 @@ export default class ScheduledMaintenanceLog extends BaseModel {
type: TableColumnType.Markdown,
required: true,
title: "Log (in Markdown)",
description: "Log of the entire scheduledMaintenance state change in Markdown",
description:
"Log of the entire scheduledMaintenance state change in Markdown",
})
@Column({
type: ColumnType.Markdown,
Expand All @@ -342,7 +339,6 @@ export default class ScheduledMaintenanceLog extends BaseModel {
})
public logInMarkdown?: string = undefined;


@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Expand Down Expand Up @@ -371,7 +367,6 @@ export default class ScheduledMaintenanceLog extends BaseModel {
})
public moreInformationInMarkdown?: string = undefined;


@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Expand All @@ -398,5 +393,6 @@ export default class ScheduledMaintenanceLog extends BaseModel {
nullable: false,
unique: false,
})
public scheduledMaintenanceLogEvent?: ScheduledMaintenanceLogEvent = undefined;
public scheduledMaintenanceLogEvent?: ScheduledMaintenanceLogEvent =
undefined;
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,51 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MigrationName1736365532085 implements MigrationInterface {
public name = 'MigrationName1736365532085'
public name = "MigrationName1736365532085";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "ScheduledMaintenanceLog" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "version" integer NOT NULL, "projectId" uuid NOT NULL, "scheduledMaintenanceId" uuid NOT NULL, "createdByUserId" uuid, "deletedByUserId" uuid, "logInMarkdown" text NOT NULL, "moreInformationInMarkdown" text NOT NULL, "scheduledMaintenanceLogEvent" character varying NOT NULL, CONSTRAINT "PK_27b89f28bf48418fabba9a1ea14" PRIMARY KEY ("_id"))`);
await queryRunner.query(`CREATE INDEX "IDX_9239de1ee33f9505c30f255a99" ON "ScheduledMaintenanceLog" ("projectId") `);
await queryRunner.query(`CREATE INDEX "IDX_58e403ba261dfa94addb5f04d3" ON "ScheduledMaintenanceLog" ("scheduledMaintenanceId") `);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceLog" ADD CONSTRAINT "FK_9239de1ee33f9505c30f255a994" FOREIGN KEY ("projectId") REFERENCES "Project"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceLog" ADD CONSTRAINT "FK_58e403ba261dfa94addb5f04d36" FOREIGN KEY ("scheduledMaintenanceId") REFERENCES "ScheduledMaintenance"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceLog" ADD CONSTRAINT "FK_9152528e4f7f59adaba3e9bc41f" FOREIGN KEY ("createdByUserId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceLog" ADD CONSTRAINT "FK_a957f435d1504f41808f20a2c45" FOREIGN KEY ("deletedByUserId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceLog" DROP CONSTRAINT "FK_a957f435d1504f41808f20a2c45"`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceLog" DROP CONSTRAINT "FK_9152528e4f7f59adaba3e9bc41f"`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceLog" DROP CONSTRAINT "FK_58e403ba261dfa94addb5f04d36"`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceLog" DROP CONSTRAINT "FK_9239de1ee33f9505c30f255a994"`);
await queryRunner.query(`DROP INDEX "public"."IDX_58e403ba261dfa94addb5f04d3"`);
await queryRunner.query(`DROP INDEX "public"."IDX_9239de1ee33f9505c30f255a99"`);
await queryRunner.query(`DROP TABLE "ScheduledMaintenanceLog"`);
}
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "ScheduledMaintenanceLog" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "version" integer NOT NULL, "projectId" uuid NOT NULL, "scheduledMaintenanceId" uuid NOT NULL, "createdByUserId" uuid, "deletedByUserId" uuid, "logInMarkdown" text NOT NULL, "moreInformationInMarkdown" text NOT NULL, "scheduledMaintenanceLogEvent" character varying NOT NULL, CONSTRAINT "PK_27b89f28bf48418fabba9a1ea14" PRIMARY KEY ("_id"))`,
);
await queryRunner.query(
`CREATE INDEX "IDX_9239de1ee33f9505c30f255a99" ON "ScheduledMaintenanceLog" ("projectId") `,
);
await queryRunner.query(
`CREATE INDEX "IDX_58e403ba261dfa94addb5f04d3" ON "ScheduledMaintenanceLog" ("scheduledMaintenanceId") `,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenanceLog" ADD CONSTRAINT "FK_9239de1ee33f9505c30f255a994" FOREIGN KEY ("projectId") REFERENCES "Project"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenanceLog" ADD CONSTRAINT "FK_58e403ba261dfa94addb5f04d36" FOREIGN KEY ("scheduledMaintenanceId") REFERENCES "ScheduledMaintenance"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenanceLog" ADD CONSTRAINT "FK_9152528e4f7f59adaba3e9bc41f" FOREIGN KEY ("createdByUserId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenanceLog" ADD CONSTRAINT "FK_a957f435d1504f41808f20a2c45" FOREIGN KEY ("deletedByUserId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenanceLog" DROP CONSTRAINT "FK_a957f435d1504f41808f20a2c45"`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenanceLog" DROP CONSTRAINT "FK_9152528e4f7f59adaba3e9bc41f"`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenanceLog" DROP CONSTRAINT "FK_58e403ba261dfa94addb5f04d36"`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenanceLog" DROP CONSTRAINT "FK_9239de1ee33f9505c30f255a994"`,
);
await queryRunner.query(
`DROP INDEX "public"."IDX_58e403ba261dfa94addb5f04d3"`,
);
await queryRunner.query(
`DROP INDEX "public"."IDX_9239de1ee33f9505c30f255a99"`,
);
await queryRunner.query(`DROP TABLE "ScheduledMaintenanceLog"`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,5 @@ export default [
MigrationName1734435866602,
MigrationName1736364478985,
MigrationName1736364957990,
MigrationName1736365532085
MigrationName1736365532085,
];
1 change: 0 additions & 1 deletion Common/Types/Permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ enum Permission {
ReadIncidentLog = "ReadIncidentLog",
DeleteIncidentLog = "DeleteIncidentLog",


CreateScheduledMaintenanceLog = "CreateScheduledMaintenanceLog",
EditScheduledMaintenanceLog = "EditScheduledMaintenanceLog",
ReadScheduledMaintenanceLog = "ReadScheduledMaintenanceLog",
Expand Down

0 comments on commit 2113ffe

Please sign in to comment.