Create 1718263333866-update_table_posmaster_add_role.ts

This commit is contained in:
AnandaTon 2024-06-13 14:31:37 +07:00
parent 693afa4e5f
commit a7d13ac00b

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTablePosmasterAddRole1718263333866 implements MigrationInterface {
name = 'UpdateTablePosmasterAddRole1718263333866'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`authRoleId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง authRole'`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD UNIQUE INDEX \`IDX_a059796d095e79ba5b20407859\` (\`authRoleId\`)`);
await queryRunner.query(`CREATE UNIQUE INDEX \`REL_a059796d095e79ba5b20407859\` ON \`posMaster\` (\`authRoleId\`)`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_a059796d095e79ba5b20407859f\` FOREIGN KEY (\`authRoleId\`) REFERENCES \`authRole\`(\`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_a059796d095e79ba5b20407859f\``);
await queryRunner.query(`DROP INDEX \`REL_a059796d095e79ba5b20407859\` ON \`posMaster\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP INDEX \`IDX_a059796d095e79ba5b20407859\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`authRoleId\``);
}
}