diff --git a/src/data-source.ts b/src/data-source.ts index a78ab3c..f1701c4 100644 --- a/src/data-source.ts +++ b/src/data-source.ts @@ -29,6 +29,9 @@ import { memberQualifications } from "./entity/memberQualifications"; import { membership } from "./entity/membership"; import { Memberdata1726301836849 } from "./migrations/1726301836849-memberdata"; import { CommunicationFields1727439800630 } from "./migrations/1727439800630-communicationFields"; +import { calendar } from "./entity/calendar"; +import { calendarType } from "./entity/calendarType"; +import { Calendar1729947763295 } from "./migrations/1729947763295-calendar"; const dataSource = new DataSource({ type: DB_TYPE as any, @@ -58,6 +61,8 @@ const dataSource = new DataSource({ memberExecutivePositions, memberQualifications, membership, + calendar, + calendarType, ], migrations: [ Initial1724317398939, @@ -68,6 +73,7 @@ const dataSource = new DataSource({ MemberBaseData1725435669492, Memberdata1726301836849, CommunicationFields1727439800630, + Calendar1729947763295, ], migrationsRun: true, migrationsTransactionMode: "each", diff --git a/src/entity/calendar.ts b/src/entity/calendar.ts new file mode 100644 index 0000000..1d1852a --- /dev/null +++ b/src/entity/calendar.ts @@ -0,0 +1,30 @@ +import { Column, Entity, ManyToOne, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm"; +import { calendarType } from "./calendarType"; + +@Entity() +export class calendar { + @PrimaryGeneratedColumn("increment") + id: number; + + @Column({ type: "date", nullable: false }) + date: Date; + + @Column({ type: "timestamp", nullable: true }) + starttime: Date; + + @Column({ type: "datetime", nullable: true }) + endtime: Date; + + @Column({ type: "varchar", length: 255, nullable: false }) + title: string; + + @Column({ type: "text", nullable: true }) + content: string; + + @ManyToOne(() => calendarType, (t) => t.calendar, { + nullable: false, + onDelete: "RESTRICT", + onUpdate: "RESTRICT", + }) + type: calendarType; +} diff --git a/src/entity/calendarType.ts b/src/entity/calendarType.ts new file mode 100644 index 0000000..f7184ef --- /dev/null +++ b/src/entity/calendarType.ts @@ -0,0 +1,21 @@ +import { Column, Entity, OneToMany, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm"; +import { calendar } from "./calendar"; + +@Entity() +export class calendarType { + @PrimaryColumn({ generated: "increment", type: "int" }) + id: number; + + @Column({ type: "varchar", length: 255 }) + type: string; + + @Column({ type: "boolean" }) // none specified cal dav request + nscdr: boolean; + + @OneToMany(() => calendar, (c) => c.type, { + nullable: false, + onDelete: "RESTRICT", + onUpdate: "RESTRICT", + }) + calendar: calendar[]; +} diff --git a/src/migrations/1729947763295-calendar.ts b/src/migrations/1729947763295-calendar.ts new file mode 100644 index 0000000..ee199fc --- /dev/null +++ b/src/migrations/1729947763295-calendar.ts @@ -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 { + 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 { + 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"); + } +}