Migrate update profile &profileEmployee add isDelete

This commit is contained in:
harid 2026-04-02 13:52:39 +07:00
parent b69f8a6c08
commit a40d98c5a9
3 changed files with 35 additions and 0 deletions

View file

@ -188,6 +188,12 @@ export class Profile extends EntityBase {
})
keycloak: string;
@Column({
comment: "สถานะการถูกลบผู้ใช้งานใน keycloak",
default: false,
})
isDelete: boolean;
@Column({
comment: "ทดลองปฏิบัติหน้าที่",
default: false,

View file

@ -204,6 +204,12 @@ export class ProfileEmployee extends EntityBase {
})
keycloak: string;
@Column({
comment: "สถานะการถูกลบผู้ใช้งานใน keycloak",
default: false,
})
isDelete: boolean;
@Column({
comment: "ทดลองปฏิบัติหน้าที่",
default: false,

View file

@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateProfileAndProfileemployeeAddFieldIsdelete1775112029663 implements MigrationInterface {
name = 'UpdateProfileAndProfileemployeeAddFieldIsdelete1775112029663'
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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\``);
}
}