import { MigrationInterface, QueryRunner, Table } from "typeorm";

export class CreateTableIssues1769509622176 implements MigrationInterface {

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.createTable(new Table({
            name: "issues",
            columns: [
                { name: "id", type: "char", length: "36", isPrimary: true, isGenerated: true, generationStrategy: "uuid" },
                { name: "codeIssue", type: "varchar", length: "20", isNullable: false, comment: "รหัส issue เช่น ISS20260127001" },
                { name: "title", type: "varchar", length: "255", isNullable: false, comment: "หัวข้อ" },
                { name: "description", type: "text", isNullable: false, comment: "รายละเอียดของปัญหา" },
                { name: "system", type: "varchar", length: "50", isNullable: false, comment: "ระบบ" },
                { name: "menu", type: "varchar", length: "255", isNullable: true, comment: "เมนู" },
                { name: "org", type: "varchar", length: "500", isNullable: true, comment: "สังกัด" },
                { name: "remark", type: "text", isNullable: true, comment: "หมายเหตุ" },
                { name: "status", type: "enum", enum: ["NEW", "IN_PROGRESS", "RESOLVED", "CLOSED"], default: "'NEW'", comment: "สถานะการแก้ไขปัญหา" },
                { name: "createdUserId", type: "char", length: "40", isNullable: false, default: "'00000000-0000-0000-0000-000000000000'", comment: "User Id ที่สร้างข้อมูล" },
                { name: "createdFullName", type: "varchar", length: "200", isNullable: false, default: "'System Administrator'", comment: "ชื่อ User ที่สร้างข้อมูล" },
                { name: "createdAt", type: "timestamp", default: "CURRENT_TIMESTAMP", comment: "สร้างข้อมูลเมื่อ" },
                { name: "lastUpdateUserId", type: "char", length: "40", isNullable: false, default: "'00000000-0000-0000-0000-000000000000'", comment: "User Id ที่แก้ไขข้อมูล" },
                { name: "lastUpdateFullName", type: "varchar", length: "200", isNullable: false, default: "'System Administrator'", comment: "ชื่อ User ที่แก้ไขข้อมูลล่าสุด" },
                { name: "lastUpdatedAt", type: "timestamp", default: "CURRENT_TIMESTAMP", comment: "แก้ไขข้อมูลล่าสุดเมื่อ" },
                
            ],
        }), true);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.dropTable("issues");
    }

}
