ff-admin-server/src/migrations/1729347911107-protocol.ts

204 lines
7.6 KiB
TypeScript
Raw Normal View History

2024-10-10 14:44:41 +02:00
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
import { DB_TYPE } from "../env.defaults";
2024-10-19 16:35:01 +02:00
export class Protocol1729347911107 implements MigrationInterface {
name = "Protocol1729347911107";
2024-10-10 14:44:41 +02:00
public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
2024-10-19 16:35:01 +02:00
await queryRunner.createTable(
new Table({
name: "protocol",
columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "title", type: "varchar", length: "255", isNullable: false },
{ name: "date", type: "date", isNullable: false },
2024-10-29 15:23:22 +01:00
{ name: "starttime", type: "time", isNullable: true },
{ name: "endtime", type: "time", isNullable: true },
2024-10-19 16:35:01 +02:00
{ name: "summary", type: "text", isNullable: true },
],
}),
true
);
2024-10-10 14:44:41 +02:00
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 },
2024-10-19 16:35:01 +02:00
{ name: "context", type: "text", default: "''", isNullable: false },
2024-10-10 14:44:41 +02:00
{ name: "protocolId", type: variableType_int, isNullable: false },
],
}),
true
);
await queryRunner.createTable(
new Table({
2024-10-19 16:35:01 +02:00
name: "protocol_decision",
2024-10-10 14:44:41 +02:00
columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "topic", type: "varchar", length: "255", isNullable: false },
2024-10-19 16:35:01 +02:00
{ name: "context", type: "text", default: "''", isNullable: false },
2024-10-10 14:44:41 +02:00
{ 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({
2024-10-19 16:35:01 +02:00
name: "protocol_voting",
2024-10-10 14:44:41 +02:00
columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "topic", type: "varchar", length: "255", isNullable: false },
2024-10-19 16:35:01 +02:00
{ name: "context", type: "text", default: "''", isNullable: false },
2024-10-10 14:44:41 +02:00
{ 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
);
2024-10-19 16:35:01 +02:00
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
);
2024-10-10 14:44:41 +02:00
await queryRunner.createForeignKey(
"protocol_agenda",
new TableForeignKey({
columnNames: ["protocolId"],
referencedColumnNames: ["id"],
referencedTableName: "protocol",
onDelete: "CASCADE",
onUpdate: "RESTRICT",
})
);
await queryRunner.createForeignKey(
2024-10-19 16:35:01 +02:00
"protocol_decision",
2024-10-10 14:44:41 +02:00
new TableForeignKey({
columnNames: ["protocolId"],
referencedColumnNames: ["id"],
referencedTableName: "protocol",
onDelete: "CASCADE",
onUpdate: "RESTRICT",
})
);
await queryRunner.createForeignKey(
2024-10-19 16:35:01 +02:00
"protocol_voting",
2024-10-10 14:44:41 +02:00
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",
})
);
2024-10-19 16:35:01 +02:00
await queryRunner.createForeignKey(
"protocol_printout",
new TableForeignKey({
columnNames: ["protocolId"],
referencedColumnNames: ["id"],
referencedTableName: "protocol",
onDelete: "CASCADE",
onUpdate: "RESTRICT",
})
);
2024-10-10 14:44:41 +02:00
}
public async down(queryRunner: QueryRunner): Promise<void> {
2024-10-19 16:35:01 +02:00
const tableProtocolVotings = await queryRunner.getTable("protocol_voting");
2024-10-10 14:44:41 +02:00
const foreignKeyProtocolVotings = tableProtocolVotings.foreignKeys.find(
(fk) => fk.columnNames.indexOf("protocolId") !== -1
);
2024-10-19 16:35:01 +02:00
await queryRunner.dropForeignKey("protocol_voting", foreignKeyProtocolVotings);
2024-10-10 14:44:41 +02:00
2024-10-19 16:35:01 +02:00
const tableProtocolDecisions = await queryRunner.getTable("protocol_decision");
2024-10-10 14:44:41 +02:00
const foreignKeyProtocolDecisions = tableProtocolDecisions.foreignKeys.find(
(fk) => fk.columnNames.indexOf("protocolId") !== -1
);
2024-10-19 16:35:01 +02:00
await queryRunner.dropForeignKey("protocol_decision", foreignKeyProtocolDecisions);
2024-10-10 14:44:41 +02:00
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);
2024-10-19 16:35:01 +02:00
const tableProtocolPrintout = await queryRunner.getTable("protocol_printout");
const foreignKeyProtocolPrintout = tableProtocolPrintout.foreignKeys.find(
(fk) => fk.columnNames.indexOf("protocolId") !== -1
);
await queryRunner.dropForeignKey("protocol_printout", foreignKeyProtocolPrintout);
await queryRunner.dropTable("protocol_printout");
await queryRunner.dropTable("protocol_voting");
2024-10-10 14:44:41 +02:00
await queryRunner.dropTable("protocol_presence");
2024-10-19 16:35:01 +02:00
await queryRunner.dropTable("protocol_decision");
2024-10-10 14:44:41 +02:00
await queryRunner.dropTable("protocol_agenda");
2024-10-19 16:35:01 +02:00
await queryRunner.dropTable("protocol");
2024-10-10 14:44:41 +02:00
}
}