feat: add declaredAt field to Incident model with migration and default value

This commit is contained in:
Nawaz Dhandala 2025-11-28 10:12:43 +00:00
parent 66efe2d2fa
commit ac66cee4aa
No known key found for this signature in database
GPG key ID: 96C5DCA24769DBCA
4 changed files with 26 additions and 3 deletions

View file

@ -250,15 +250,16 @@ export default class Incident extends BaseModel {
})
@Index()
@TableColumn({
required: false,
required: true,
type: TableColumnType.Date,
title: "Declared At",
description: "Date and time when this incident was declared.",
isDefaultValueColumn: false,
isDefaultValueColumn: true,
})
@Column({
type: ColumnType.Date,
nullable: true,
nullable: false,
default: () => "now()",
})
public declaredAt?: Date = undefined;

View file

@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class MigrationName1764324618043 implements MigrationInterface {
public name = 'MigrationName1764324618043'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "Incident" ADD "declaredAt" TIMESTAMP WITH TIME ZONE`);
await queryRunner.query(`UPDATE "Incident" SET "declaredAt" = "createdAt" WHERE "declaredAt" IS NULL`);
await queryRunner.query(`ALTER TABLE "Incident" ALTER COLUMN "declaredAt" SET DEFAULT now()`);
await queryRunner.query(`ALTER TABLE "Incident" ALTER COLUMN "declaredAt" SET NOT NULL`);
await queryRunner.query(`CREATE INDEX "IDX_b26979b9f119310661734465a4" ON "Incident" ("declaredAt") `);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "public"."IDX_b26979b9f119310661734465a4"`);
await queryRunner.query(`ALTER TABLE "Incident" DROP COLUMN "declaredAt"`);
}
}

View file

@ -186,6 +186,7 @@ import { MigrationName1763471659817 } from "./1763471659817-MigrationName";
import { MigrationName1763477560906 } from "./1763477560906-MigrationName";
import { MigrationName1763480947474 } from "./1763480947474-MigrationName";
import { MigrationName1763643080445 } from "./1763643080445-MigrationName";
import { MigrationName1764324618043 } from "./1764324618043-MigrationName";
export default [
InitialMigration,
@ -376,4 +377,5 @@ export default [
MigrationName1763477560906,
MigrationName1763480947474,
MigrationName1763643080445,
MigrationName1764324618043
];

1
vscode-copilot-chat Submodule

@ -0,0 +1 @@
Subproject commit 17b20ceffad14beca81f3c06c1e267d58aa0ffc5