printout
This commit is contained in:
parent
58213923e5
commit
9da2a98f55
12 changed files with 341 additions and 54 deletions
44
src/migrations/1729344771434-protocolPrintout.ts
Normal file
44
src/migrations/1729344771434-protocolPrintout.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
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");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue