From a40d98c5a9ec5ccefc83449827f02d98084596d7 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 2 Apr 2026 13:52:39 +0700 Subject: [PATCH] Migrate update profile &profileEmployee add isDelete --- src/entities/Profile.ts | 6 +++++ src/entities/ProfileEmployee.ts | 6 +++++ ..._and_profileemployee_add_field_isdelete.ts | 23 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/migration/1775112029663-update_profile_and_profileemployee_add_field_isdelete.ts diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index fe2f55d6..72a1d505 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -188,6 +188,12 @@ export class Profile extends EntityBase { }) keycloak: string; + @Column({ + comment: "สถานะการถูกลบผู้ใช้งานใน keycloak", + default: false, + }) + isDelete: boolean; + @Column({ comment: "ทดลองปฏิบัติหน้าที่", default: false, diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 2c3f06e4..11c2159b 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -204,6 +204,12 @@ export class ProfileEmployee extends EntityBase { }) keycloak: string; + @Column({ + comment: "สถานะการถูกลบผู้ใช้งานใน keycloak", + default: false, + }) + isDelete: boolean; + @Column({ comment: "ทดลองปฏิบัติหน้าที่", default: false, diff --git a/src/migration/1775112029663-update_profile_and_profileemployee_add_field_isdelete.ts b/src/migration/1775112029663-update_profile_and_profileemployee_add_field_isdelete.ts new file mode 100644 index 00000000..706f3d59 --- /dev/null +++ b/src/migration/1775112029663-update_profile_and_profileemployee_add_field_isdelete.ts @@ -0,0 +1,23 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateProfileAndProfileemployeeAddFieldIsdelete1775112029663 implements MigrationInterface { + name = 'UpdateProfileAndProfileemployeeAddFieldIsdelete1775112029663' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`isDelete\` tinyint NOT NULL COMMENT 'สถานะการถูกลบผู้ใช้งานใน keycloak' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`isDelete\` tinyint NOT NULL COMMENT 'สถานะการถูกลบผู้ใช้งานใน keycloak' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profile\` ADD \`isDelete\` tinyint NOT NULL COMMENT 'สถานะการถูกลบผู้ใช้งานใน keycloak' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`isDelete\` tinyint NOT NULL COMMENT 'สถานะการถูกลบผู้ใช้งานใน keycloak' DEFAULT 0`); + + // Update ข้อมูลเดิม: ถ้า keycloak null → isDelete = true (1), ถ้ามีค่า → isDelete = false (0) + await queryRunner.query(`UPDATE \`profileEmployee\` SET \`isDelete\` = CASE WHEN \`keycloak\` IS NULL THEN 1 ELSE 0 END`); + await queryRunner.query(`UPDATE \`profile\` SET \`isDelete\` = CASE WHEN \`keycloak\` IS NULL THEN 1 ELSE 0 END`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`isDelete\``); + await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`isDelete\``); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`isDelete\``); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`isDelete\``); + } +}