base tables

This commit is contained in:
Julian Krauser 2024-10-26 15:08:05 +02:00
parent 72fb6fbc20
commit e7b8257336
4 changed files with 113 additions and 0 deletions

View file

@ -0,0 +1,56 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
import { DB_TYPE } from "../env.defaults";
export class Calendar1729947763295 implements MigrationInterface {
name = "Calendar1729947763295";
public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
await queryRunner.createTable(
new Table({
name: "calendar_type",
columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "type", type: "varchar", length: "255", isNullable: false },
{ name: "nscdr", type: "tinyint", isNullable: false },
],
})
);
await queryRunner.createTable(
new Table({
name: "calendar",
columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "date", type: "date", isNullable: false },
{ name: "starttime", type: "timestamp", isNullable: true },
{ name: "endtime", type: "datetime", isNullable: true },
{ name: "title", type: "varchar", length: "255", isNullable: false },
{ name: "content", type: "text", isNullable: true },
{ name: "typeId", type: variableType_int, isNullable: false },
],
})
);
await queryRunner.createForeignKey(
"calendar",
new TableForeignKey({
columnNames: ["typeId"],
referencedColumnNames: ["id"],
referencedTableName: "calendar_type",
onDelete: "RESTRICT",
onUpdate: "RESTRICT",
})
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
const table = await queryRunner.getTable("calendar");
const foreignKey = table.foreignKeys.find((fk) => fk.columnNames.indexOf("typeId") !== -1);
await queryRunner.dropForeignKey("calendar", foreignKey);
await queryRunner.dropTable("calendar");
await queryRunner.dropTable("calendar_type");
}
}