From dd74005043063f022181d2a5701d1f284e845db8 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Thu, 10 Oct 2024 14:44:41 +0200 Subject: [PATCH] protocol tables --- src/data-source.ts | 10 ++ src/entity/protocolAgenda.ts | 21 +++ src/entity/protocolDecisions.ts | 21 +++ src/entity/protocolPresence.ts | 26 +++ src/entity/protocolVotings.ts | 30 ++++ .../1728563204766-protocolTables.ts | 154 ++++++++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 src/entity/protocolAgenda.ts create mode 100644 src/entity/protocolDecisions.ts create mode 100644 src/entity/protocolPresence.ts create mode 100644 src/entity/protocolVotings.ts create mode 100644 src/migrations/1728563204766-protocolTables.ts diff --git a/src/data-source.ts b/src/data-source.ts index e1de44b..f3f08a0 100644 --- a/src/data-source.ts +++ b/src/data-source.ts @@ -32,6 +32,11 @@ import { CommunicationFields1727439800630 } from "./migrations/1727439800630-com import { protocol } from "./entity/protocol"; import { ProtocolInit1727953803404 } from "./migrations/1727953803404-protocol-init"; import { ProtocolBase1728037129072 } from "./migrations/1728037129072-protocolBase"; +import { protocolAgenda } from "./entity/protocolAgenda"; +import { protocolDecisions } from "./entity/protocolDecisions"; +import { protocolPresence } from "./entity/protocolPresence"; +import { protocolVotings } from "./entity/protocolVotings"; +import { ProtocolTables1728563204766 } from "./migrations/1728563204766-protocolTables"; const dataSource = new DataSource({ type: DB_TYPE as any, @@ -62,6 +67,10 @@ const dataSource = new DataSource({ memberQualifications, membership, protocol, + protocolAgenda, + protocolDecisions, + protocolPresence, + protocolVotings, ], migrations: [ Initial1724317398939, @@ -74,6 +83,7 @@ const dataSource = new DataSource({ CommunicationFields1727439800630, ProtocolInit1727953803404, ProtocolBase1728037129072, + ProtocolTables1728563204766, ], migrationsRun: true, migrationsTransactionMode: "each", diff --git a/src/entity/protocolAgenda.ts b/src/entity/protocolAgenda.ts new file mode 100644 index 0000000..c3396c7 --- /dev/null +++ b/src/entity/protocolAgenda.ts @@ -0,0 +1,21 @@ +import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; +import { protocol } from "./protocol"; + +@Entity() +export class protocolAgenda { + @PrimaryGeneratedColumn("increment") + id: string; + + @Column({ type: "varchar", length: 255 }) + topic: string; + + @Column({ type: "varchar", length: 255, default: "" }) + context: string; + + @ManyToOne(() => protocol, { + nullable: false, + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + protocol: protocol; +} diff --git a/src/entity/protocolDecisions.ts b/src/entity/protocolDecisions.ts new file mode 100644 index 0000000..fed4e2e --- /dev/null +++ b/src/entity/protocolDecisions.ts @@ -0,0 +1,21 @@ +import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; +import { protocol } from "./protocol"; + +@Entity() +export class protocolDecisions { + @PrimaryGeneratedColumn("increment") + id: string; + + @Column({ type: "varchar", length: 255 }) + topic: string; + + @Column({ type: "varchar", length: 255, default: "" }) + context: string; + + @ManyToOne(() => protocol, { + nullable: false, + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + protocol: protocol; +} diff --git a/src/entity/protocolPresence.ts b/src/entity/protocolPresence.ts new file mode 100644 index 0000000..975ee0c --- /dev/null +++ b/src/entity/protocolPresence.ts @@ -0,0 +1,26 @@ +import { Column, Entity, ManyToOne, PrimaryColumn } from "typeorm"; +import { protocol } from "./protocol"; +import { member } from "./member"; + +@Entity() +export class protocolPresence { + @PrimaryColumn() + memberId: string; + + @PrimaryColumn() + protocolId: string; + + @ManyToOne(() => member, { + nullable: false, + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + member: member; + + @ManyToOne(() => protocol, { + nullable: false, + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + protocol: protocol; +} diff --git a/src/entity/protocolVotings.ts b/src/entity/protocolVotings.ts new file mode 100644 index 0000000..b2a03c7 --- /dev/null +++ b/src/entity/protocolVotings.ts @@ -0,0 +1,30 @@ +import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; +import { protocol } from "./protocol"; + +@Entity() +export class protocolVotings { + @PrimaryGeneratedColumn("increment") + id: string; + + @Column({ type: "varchar", length: 255 }) + topic: string; + + @Column({ type: "varchar", length: 255, default: "" }) + context: string; + + @Column({ type: "int", default: 0 }) + favour: number; + + @Column({ type: "int", default: 0 }) + abstain: number; + + @Column({ type: "int", default: 0 }) + against: number; + + @ManyToOne(() => protocol, { + nullable: false, + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + protocol: protocol; +} diff --git a/src/migrations/1728563204766-protocolTables.ts b/src/migrations/1728563204766-protocolTables.ts new file mode 100644 index 0000000..92b6d19 --- /dev/null +++ b/src/migrations/1728563204766-protocolTables.ts @@ -0,0 +1,154 @@ +import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; +import { DB_TYPE } from "../env.defaults"; + +export class ProtocolTables1728563204766 implements MigrationInterface { + name = "ProtocolTables1728563204766"; + + public async up(queryRunner: QueryRunner): Promise { + const variableType_int = DB_TYPE == "mysql" ? "int" : "integer"; + + await queryRunner.createTable( + new Table({ + name: "protocol_agenda", + columns: [ + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "topic", type: "varchar", length: "255", isNullable: false }, + { name: "context", type: "varchar", length: "255", default: "''", isNullable: false }, + { name: "protocolId", type: variableType_int, isNullable: false }, + ], + }), + true + ); + + await queryRunner.createTable( + new Table({ + name: "protocol_decisions", + columns: [ + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "topic", type: "varchar", length: "255", isNullable: false }, + { name: "context", type: "varchar", length: "255", default: "''", isNullable: false }, + { name: "protocolId", type: variableType_int, isNullable: false }, + ], + }), + true + ); + + await queryRunner.createTable( + new Table({ + name: "protocol_presence", + columns: [ + { name: "memberId", type: variableType_int, isPrimary: true, isNullable: false }, + { name: "protocolId", type: variableType_int, isPrimary: true, isNullable: false }, + ], + }), + true + ); + + await queryRunner.createTable( + new Table({ + name: "protocol_votings", + columns: [ + { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, + { name: "topic", type: "varchar", length: "255", isNullable: false }, + { name: "context", type: "varchar", length: "255", default: "''", isNullable: false }, + { name: "favour", type: variableType_int, default: 0, isNullable: false }, + { name: "abstain", type: variableType_int, default: 0, isNullable: false }, + { name: "against", type: variableType_int, default: 0, isNullable: false }, + { name: "protocolId", type: variableType_int, isNullable: false }, + ], + }), + true + ); + + await queryRunner.createForeignKey( + "protocol_agenda", + new TableForeignKey({ + columnNames: ["protocolId"], + referencedColumnNames: ["id"], + referencedTableName: "protocol", + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + ); + + await queryRunner.createForeignKey( + "protocol_decisions", + new TableForeignKey({ + columnNames: ["protocolId"], + referencedColumnNames: ["id"], + referencedTableName: "protocol", + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + ); + + await queryRunner.createForeignKey( + "protocol_votings", + new TableForeignKey({ + columnNames: ["protocolId"], + referencedColumnNames: ["id"], + referencedTableName: "protocol", + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + ); + + await queryRunner.createForeignKey( + "protocol_presence", + new TableForeignKey({ + columnNames: ["protocolId"], + referencedColumnNames: ["id"], + referencedTableName: "protocol", + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + ); + await queryRunner.createForeignKey( + "protocol_presence", + new TableForeignKey({ + columnNames: ["memberId"], + referencedColumnNames: ["id"], + referencedTableName: "member", + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + ); + } + + public async down(queryRunner: QueryRunner): Promise { + const tableProtocolVotings = await queryRunner.getTable("protocol_votings"); + const foreignKeyProtocolVotings = tableProtocolVotings.foreignKeys.find( + (fk) => fk.columnNames.indexOf("protocolId") !== -1 + ); + await queryRunner.dropForeignKey("protocol_votings", foreignKeyProtocolVotings); + + const tableProtocolDecisions = await queryRunner.getTable("protocol_decisions"); + const foreignKeyProtocolDecisions = tableProtocolDecisions.foreignKeys.find( + (fk) => fk.columnNames.indexOf("protocolId") !== -1 + ); + await queryRunner.dropForeignKey("protocol_decisions", foreignKeyProtocolDecisions); + + const tableProtocolAgenda = await queryRunner.getTable("protocol_agenda"); + const foreignKeyProtocolAgenda = tableProtocolAgenda.foreignKeys.find( + (fk) => fk.columnNames.indexOf("protocolId") !== -1 + ); + await queryRunner.dropForeignKey("protocol_agenda", foreignKeyProtocolAgenda); + + const tableProtocolPresence_protcol = await queryRunner.getTable("protocol_presence"); + const foreignKeyProtocolPresence_protcol = tableProtocolPresence_protcol.foreignKeys.find( + (fk) => fk.columnNames.indexOf("protocolId") !== -1 + ); + await queryRunner.dropForeignKey("protocol_presence", foreignKeyProtocolPresence_protcol); + + const tableProtocolPresence_member = await queryRunner.getTable("protocol_presence"); + const foreignKeyProtocolPresence_member = tableProtocolPresence_member.foreignKeys.find( + (fk) => fk.columnNames.indexOf("memberId") !== -1 + ); + await queryRunner.dropForeignKey("protocol_presence", foreignKeyProtocolPresence_member); + + await queryRunner.dropTable("protocol_votings"); + await queryRunner.dropTable("protocol_presence"); + await queryRunner.dropTable("protocol_decisions"); + await queryRunner.dropTable("protocol_agenda"); + } +}