From 6f72c27d2053a8bf6f8878b04070c87a7eaacf9c Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Sat, 19 Oct 2024 16:35:01 +0200 Subject: [PATCH] squash migrations --- src/data-source.ts | 14 +-- src/migrations/1727953803404-protocol-init.ts | 26 ----- src/migrations/1728037129072-protocolBase.ts | 38 ------- .../1728645611919-protocolTableRename.ts | 15 --- .../1728999487170-protocolTableTypes.ts | 101 ------------------ .../1729344771434-protocolPrintout.ts | 44 -------- ...colTables.ts => 1729347911107-protocol.ts} | 79 +++++++++++--- 7 files changed, 66 insertions(+), 251 deletions(-) delete mode 100644 src/migrations/1727953803404-protocol-init.ts delete mode 100644 src/migrations/1728037129072-protocolBase.ts delete mode 100644 src/migrations/1728645611919-protocolTableRename.ts delete mode 100644 src/migrations/1728999487170-protocolTableTypes.ts delete mode 100644 src/migrations/1729344771434-protocolPrintout.ts rename src/migrations/{1728563204766-protocolTables.ts => 1729347911107-protocol.ts} (64%) diff --git a/src/data-source.ts b/src/data-source.ts index 10b2991..cf9058c 100644 --- a/src/data-source.ts +++ b/src/data-source.ts @@ -30,17 +30,12 @@ import { membership } from "./entity/membership"; import { Memberdata1726301836849 } from "./migrations/1726301836849-memberdata"; import { CommunicationFields1727439800630 } from "./migrations/1727439800630-communicationFields"; import { protocol } from "./entity/protocol"; -import { ProtocolInit1727953803404 } from "./migrations/1727953803404-protocol-init"; -import { ProtocolBase1728037129072 } from "./migrations/1728037129072-protocolBase"; import { protocolAgenda } from "./entity/protocolAgenda"; import { protocolDecision } from "./entity/protocolDecision"; import { protocolPresence } from "./entity/protocolPresence"; import { protocolVoting } from "./entity/protocolVoting"; -import { ProtocolTables1728563204766 } from "./migrations/1728563204766-protocolTables"; -import { ProtocolTableRename1728645611919 } from "./migrations/1728645611919-protocolTableRename"; -import { ProtocolTableTypes1728999487170 } from "./migrations/1728999487170-protocolTableTypes"; import { protocolPrintout } from "./entity/protocolPrintout"; -import { ProtocolPrintout1729344771434 } from "./migrations/1729344771434-protocolPrintout"; +import { Protocol1729347911107 } from "./migrations/1729347911107-protocol"; const dataSource = new DataSource({ type: DB_TYPE as any, @@ -86,12 +81,7 @@ const dataSource = new DataSource({ MemberBaseData1725435669492, Memberdata1726301836849, CommunicationFields1727439800630, - ProtocolInit1727953803404, - ProtocolBase1728037129072, - ProtocolTables1728563204766, - ProtocolTableRename1728645611919, - ProtocolTableTypes1728999487170, - ProtocolPrintout1729344771434, + Protocol1729347911107, ], migrationsRun: true, migrationsTransactionMode: "each", diff --git a/src/migrations/1727953803404-protocol-init.ts b/src/migrations/1727953803404-protocol-init.ts deleted file mode 100644 index f7bd435..0000000 --- a/src/migrations/1727953803404-protocol-init.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { MigrationInterface, QueryRunner, Table } from "typeorm"; -import { DB_TYPE } from "../env.defaults"; - -export class ProtocolInit1727953803404 implements MigrationInterface { - name = "ProtocolInit1727953803404"; - - public async up(queryRunner: QueryRunner): Promise { - const variableType_int = DB_TYPE == "mysql" ? "int" : "integer"; - - 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 }, - ], - }), - true - ); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.dropTable("protocol"); - } -} diff --git a/src/migrations/1728037129072-protocolBase.ts b/src/migrations/1728037129072-protocolBase.ts deleted file mode 100644 index 23f56ea..0000000 --- a/src/migrations/1728037129072-protocolBase.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { MigrationInterface, QueryRunner, TableColumn } from "typeorm"; - -export class ProtocolBase1728037129072 implements MigrationInterface { - name = "ProtocolBase1728037129072"; - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.addColumn( - "protocol", - new TableColumn({ - name: "starttime", - type: "timestamp", - isNullable: true, - }) - ); - await queryRunner.addColumn( - "protocol", - new TableColumn({ - name: "endtime", - type: "timestamp", - isNullable: true, - }) - ); - await queryRunner.addColumn( - "protocol", - new TableColumn({ - name: "summary", - type: "text", - isNullable: true, - }) - ); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.dropColumn("protocol", "summary"); - await queryRunner.dropColumn("protocol", "endtime"); - await queryRunner.dropColumn("protocol", "starttime"); - } -} diff --git a/src/migrations/1728645611919-protocolTableRename.ts b/src/migrations/1728645611919-protocolTableRename.ts deleted file mode 100644 index 4a79c51..0000000 --- a/src/migrations/1728645611919-protocolTableRename.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class ProtocolTableRename1728645611919 implements MigrationInterface { - name = "ProtocolTableRename1728645611919"; - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.renameTable("protocol_decisions", "protocol_decision"); - await queryRunner.renameTable("protocol_votings", "protocol_voting"); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.renameTable("protocol_decision", "protocol_decisions"); - await queryRunner.renameTable("protocol_voting", "protocol_votings"); - } -} diff --git a/src/migrations/1728999487170-protocolTableTypes.ts b/src/migrations/1728999487170-protocolTableTypes.ts deleted file mode 100644 index ef739f0..0000000 --- a/src/migrations/1728999487170-protocolTableTypes.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { MigrationInterface, QueryRunner, TableColumn } from "typeorm"; - -export class ProtocolTableTypes1728999487170 implements MigrationInterface { - name = "ProtocolTableTypes1728999487170"; - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.changeColumn( - "protocol", - "summary", - new TableColumn({ - name: "summary", - type: "text", - default: "''", - isNullable: false, - }) - ); - - await queryRunner.changeColumn( - "protocol_agenda", - "context", - new TableColumn({ - name: "context", - type: "text", - default: "''", - isNullable: false, - }) - ); - - await queryRunner.changeColumn( - "protocol_decision", - "context", - new TableColumn({ - name: "context", - type: "text", - default: "''", - isNullable: false, - }) - ); - - await queryRunner.changeColumn( - "protocol_voting", - "context", - new TableColumn({ - name: "context", - type: "text", - default: "''", - isNullable: false, - }) - ); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.changeColumn( - "protocol", - "summary", - new TableColumn({ - name: "summary", - type: "varchar", - length: "255", - default: "''", - isNullable: false, - }) - ); - - await queryRunner.changeColumn( - "protocol_agenda", - "context", - new TableColumn({ - name: "context", - type: "varchar", - length: "255", - default: "''", - isNullable: false, - }) - ); - - await queryRunner.changeColumn( - "protocol_decision", - "context", - new TableColumn({ - name: "context", - type: "varchar", - length: "255", - default: "''", - isNullable: false, - }) - ); - - await queryRunner.changeColumn( - "protocol_voting", - "context", - new TableColumn({ - name: "context", - type: "varchar", - length: "255", - default: "''", - isNullable: false, - }) - ); - } -} diff --git a/src/migrations/1729344771434-protocolPrintout.ts b/src/migrations/1729344771434-protocolPrintout.ts deleted file mode 100644 index 25c50fe..0000000 --- a/src/migrations/1729344771434-protocolPrintout.ts +++ /dev/null @@ -1,44 +0,0 @@ -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 { - 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 { - 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"); - } -} diff --git a/src/migrations/1728563204766-protocolTables.ts b/src/migrations/1729347911107-protocol.ts similarity index 64% rename from src/migrations/1728563204766-protocolTables.ts rename to src/migrations/1729347911107-protocol.ts index 92b6d19..8a65a15 100644 --- a/src/migrations/1728563204766-protocolTables.ts +++ b/src/migrations/1729347911107-protocol.ts @@ -1,19 +1,34 @@ import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; import { DB_TYPE } from "../env.defaults"; -export class ProtocolTables1728563204766 implements MigrationInterface { - name = "ProtocolTables1728563204766"; +export class Protocol1729347911107 implements MigrationInterface { + name = "Protocol1729347911107"; public async up(queryRunner: QueryRunner): Promise { const variableType_int = DB_TYPE == "mysql" ? "int" : "integer"; + 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 }, + { name: "starttime", type: "timestamp", isNullable: true }, + { name: "endtime", type: "timestamp", isNullable: true }, + { name: "summary", type: "text", isNullable: true }, + ], + }), + true + ); + 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: "context", type: "text", default: "''", isNullable: false }, { name: "protocolId", type: variableType_int, isNullable: false }, ], }), @@ -22,11 +37,11 @@ export class ProtocolTables1728563204766 implements MigrationInterface { await queryRunner.createTable( new Table({ - name: "protocol_decisions", + name: "protocol_decision", 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: "context", type: "text", default: "''", isNullable: false }, { name: "protocolId", type: variableType_int, isNullable: false }, ], }), @@ -46,11 +61,11 @@ export class ProtocolTables1728563204766 implements MigrationInterface { await queryRunner.createTable( new Table({ - name: "protocol_votings", + name: "protocol_voting", 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: "context", type: "text", 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 }, @@ -60,6 +75,21 @@ export class ProtocolTables1728563204766 implements MigrationInterface { true ); + 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_agenda", new TableForeignKey({ @@ -72,7 +102,7 @@ export class ProtocolTables1728563204766 implements MigrationInterface { ); await queryRunner.createForeignKey( - "protocol_decisions", + "protocol_decision", new TableForeignKey({ columnNames: ["protocolId"], referencedColumnNames: ["id"], @@ -83,7 +113,7 @@ export class ProtocolTables1728563204766 implements MigrationInterface { ); await queryRunner.createForeignKey( - "protocol_votings", + "protocol_voting", new TableForeignKey({ columnNames: ["protocolId"], referencedColumnNames: ["id"], @@ -113,20 +143,31 @@ export class ProtocolTables1728563204766 implements MigrationInterface { onUpdate: "RESTRICT", }) ); + + await queryRunner.createForeignKey( + "protocol_printout", + new TableForeignKey({ + columnNames: ["protocolId"], + referencedColumnNames: ["id"], + referencedTableName: "protocol", + onDelete: "CASCADE", + onUpdate: "RESTRICT", + }) + ); } public async down(queryRunner: QueryRunner): Promise { - const tableProtocolVotings = await queryRunner.getTable("protocol_votings"); + const tableProtocolVotings = await queryRunner.getTable("protocol_voting"); const foreignKeyProtocolVotings = tableProtocolVotings.foreignKeys.find( (fk) => fk.columnNames.indexOf("protocolId") !== -1 ); - await queryRunner.dropForeignKey("protocol_votings", foreignKeyProtocolVotings); + await queryRunner.dropForeignKey("protocol_voting", foreignKeyProtocolVotings); - const tableProtocolDecisions = await queryRunner.getTable("protocol_decisions"); + const tableProtocolDecisions = await queryRunner.getTable("protocol_decision"); const foreignKeyProtocolDecisions = tableProtocolDecisions.foreignKeys.find( (fk) => fk.columnNames.indexOf("protocolId") !== -1 ); - await queryRunner.dropForeignKey("protocol_decisions", foreignKeyProtocolDecisions); + await queryRunner.dropForeignKey("protocol_decision", foreignKeyProtocolDecisions); const tableProtocolAgenda = await queryRunner.getTable("protocol_agenda"); const foreignKeyProtocolAgenda = tableProtocolAgenda.foreignKeys.find( @@ -146,9 +187,17 @@ export class ProtocolTables1728563204766 implements MigrationInterface { ); await queryRunner.dropForeignKey("protocol_presence", foreignKeyProtocolPresence_member); - await queryRunner.dropTable("protocol_votings"); + 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"); await queryRunner.dropTable("protocol_presence"); - await queryRunner.dropTable("protocol_decisions"); + await queryRunner.dropTable("protocol_decision"); await queryRunner.dropTable("protocol_agenda"); + await queryRunner.dropTable("protocol"); } }