migrate profile

This commit is contained in:
Kittapath 2024-02-06 10:15:16 +07:00
parent 6804332f40
commit 02c42c2068

View file

@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableProfile1707189271932 implements MigrationInterface {
name = 'AddTableProfile1707189271932'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`profile\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`prefix\` varchar(40) NULL COMMENT 'คำนำหน้าชื่อ', \`firstName\` varchar(255) NULL COMMENT 'ชื่อ', \`lastName\` varchar(255) NULL COMMENT 'นามสกุล', \`citizenId\` int NULL COMMENT 'เลขประจำตัวประชาชน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_1acc4ba5b4af308f0d8a1b7b249\` FOREIGN KEY (\`profileIdCurrentHolder\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_9d29f52dcf499db3a5e8209b6dc\` FOREIGN KEY (\`profileIdNextHolder\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_9d29f52dcf499db3a5e8209b6dc\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_1acc4ba5b4af308f0d8a1b7b249\``);
await queryRunner.query(`DROP TABLE \`profile\``);
}
}