ff-admin-server/src/migrations/1729344771434-protocolPrintout.ts

45 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-10-19 16:24:41 +02:00
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
import { DB_TYPE } from "../env.defaults";
export class ProtocolPrintout1729344771434 implements MigrationInterface {
name = "ProtocolPrintout1729344771434";
public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
await queryRunner.createTable(
new Table({
name: "protocol_printout",
columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "title", type: "varchar", length: "255", isNullable: false },
{ name: "iteration", type: variableType_int, default: 1, isNullable: false },
{ name: "filename", type: "varchar", length: "255", isNullable: false },
{ name: "createdAt", type: "datetime(6)", isNullable: false, default: "CURRENT_TIMESTAMP(6)" },
{ name: "protocolId", type: variableType_int, isNullable: false },
],
}),
true
);
await queryRunner.createForeignKey(
"protocol_printout",
new TableForeignKey({
columnNames: ["protocolId"],
referencedColumnNames: ["id"],
referencedTableName: "protocol",
onDelete: "CASCADE",
onUpdate: "RESTRICT",
})
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
const table = await queryRunner.getTable("protocol_printout");
const foreignKey = table.foreignKeys.find((fk) => fk.columnNames.indexOf("protocolId") !== -1);
await queryRunner.dropForeignKey("protocol_printout", foreignKey);
await queryRunner.dropTable("protocol_printout");
}
}