diff --git a/src/migration/1718263333866-update_table_posmaster_add_role.ts b/src/migration/1718263333866-update_table_posmaster_add_role.ts new file mode 100644 index 00000000..f6853014 --- /dev/null +++ b/src/migration/1718263333866-update_table_posmaster_add_role.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTablePosmasterAddRole1718263333866 implements MigrationInterface { + name = 'UpdateTablePosmasterAddRole1718263333866' + + public async up(queryRunner: QueryRunner): Promise { + 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 { + 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\``); + } + +}