squash migrations

This commit is contained in:
Julian Krauser 2024-10-19 16:35:01 +02:00
parent 9da2a98f55
commit 6f72c27d20
7 changed files with 66 additions and 251 deletions

View file

@ -30,17 +30,12 @@ import { membership } from "./entity/membership";
import { Memberdata1726301836849 } from "./migrations/1726301836849-memberdata"; import { Memberdata1726301836849 } from "./migrations/1726301836849-memberdata";
import { CommunicationFields1727439800630 } from "./migrations/1727439800630-communicationFields"; import { CommunicationFields1727439800630 } from "./migrations/1727439800630-communicationFields";
import { protocol } from "./entity/protocol"; import { protocol } from "./entity/protocol";
import { ProtocolInit1727953803404 } from "./migrations/1727953803404-protocol-init";
import { ProtocolBase1728037129072 } from "./migrations/1728037129072-protocolBase";
import { protocolAgenda } from "./entity/protocolAgenda"; import { protocolAgenda } from "./entity/protocolAgenda";
import { protocolDecision } from "./entity/protocolDecision"; import { protocolDecision } from "./entity/protocolDecision";
import { protocolPresence } from "./entity/protocolPresence"; import { protocolPresence } from "./entity/protocolPresence";
import { protocolVoting } from "./entity/protocolVoting"; 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 { protocolPrintout } from "./entity/protocolPrintout";
import { ProtocolPrintout1729344771434 } from "./migrations/1729344771434-protocolPrintout"; import { Protocol1729347911107 } from "./migrations/1729347911107-protocol";
const dataSource = new DataSource({ const dataSource = new DataSource({
type: DB_TYPE as any, type: DB_TYPE as any,
@ -86,12 +81,7 @@ const dataSource = new DataSource({
MemberBaseData1725435669492, MemberBaseData1725435669492,
Memberdata1726301836849, Memberdata1726301836849,
CommunicationFields1727439800630, CommunicationFields1727439800630,
ProtocolInit1727953803404, Protocol1729347911107,
ProtocolBase1728037129072,
ProtocolTables1728563204766,
ProtocolTableRename1728645611919,
ProtocolTableTypes1728999487170,
ProtocolPrintout1729344771434,
], ],
migrationsRun: true, migrationsRun: true,
migrationsTransactionMode: "each", migrationsTransactionMode: "each",

View file

@ -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<void> {
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<void> {
await queryRunner.dropTable("protocol");
}
}

View file

@ -1,38 +0,0 @@
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
export class ProtocolBase1728037129072 implements MigrationInterface {
name = "ProtocolBase1728037129072";
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
await queryRunner.dropColumn("protocol", "summary");
await queryRunner.dropColumn("protocol", "endtime");
await queryRunner.dropColumn("protocol", "starttime");
}
}

View file

@ -1,15 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class ProtocolTableRename1728645611919 implements MigrationInterface {
name = "ProtocolTableRename1728645611919";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.renameTable("protocol_decisions", "protocol_decision");
await queryRunner.renameTable("protocol_votings", "protocol_voting");
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.renameTable("protocol_decision", "protocol_decisions");
await queryRunner.renameTable("protocol_voting", "protocol_votings");
}
}

View file

@ -1,101 +0,0 @@
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
export class ProtocolTableTypes1728999487170 implements MigrationInterface {
name = "ProtocolTableTypes1728999487170";
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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,
})
);
}
}

View file

@ -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<void> {
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<void> {
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");
}
}

View file

@ -1,19 +1,34 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm"; import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
import { DB_TYPE } from "../env.defaults"; import { DB_TYPE } from "../env.defaults";
export class ProtocolTables1728563204766 implements MigrationInterface { export class Protocol1729347911107 implements MigrationInterface {
name = "ProtocolTables1728563204766"; name = "Protocol1729347911107";
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer"; 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( await queryRunner.createTable(
new Table({ new Table({
name: "protocol_agenda", name: "protocol_agenda",
columns: [ columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "topic", type: "varchar", length: "255", isNullable: false }, { 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 }, { name: "protocolId", type: variableType_int, isNullable: false },
], ],
}), }),
@ -22,11 +37,11 @@ export class ProtocolTables1728563204766 implements MigrationInterface {
await queryRunner.createTable( await queryRunner.createTable(
new Table({ new Table({
name: "protocol_decisions", name: "protocol_decision",
columns: [ columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "topic", type: "varchar", length: "255", isNullable: false }, { 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 }, { name: "protocolId", type: variableType_int, isNullable: false },
], ],
}), }),
@ -46,11 +61,11 @@ export class ProtocolTables1728563204766 implements MigrationInterface {
await queryRunner.createTable( await queryRunner.createTable(
new Table({ new Table({
name: "protocol_votings", name: "protocol_voting",
columns: [ columns: [
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" }, { name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "topic", type: "varchar", length: "255", isNullable: false }, { 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: "favour", type: variableType_int, default: 0, isNullable: false },
{ name: "abstain", 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: "against", type: variableType_int, default: 0, isNullable: false },
@ -60,6 +75,21 @@ export class ProtocolTables1728563204766 implements MigrationInterface {
true 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( await queryRunner.createForeignKey(
"protocol_agenda", "protocol_agenda",
new TableForeignKey({ new TableForeignKey({
@ -72,7 +102,7 @@ export class ProtocolTables1728563204766 implements MigrationInterface {
); );
await queryRunner.createForeignKey( await queryRunner.createForeignKey(
"protocol_decisions", "protocol_decision",
new TableForeignKey({ new TableForeignKey({
columnNames: ["protocolId"], columnNames: ["protocolId"],
referencedColumnNames: ["id"], referencedColumnNames: ["id"],
@ -83,7 +113,7 @@ export class ProtocolTables1728563204766 implements MigrationInterface {
); );
await queryRunner.createForeignKey( await queryRunner.createForeignKey(
"protocol_votings", "protocol_voting",
new TableForeignKey({ new TableForeignKey({
columnNames: ["protocolId"], columnNames: ["protocolId"],
referencedColumnNames: ["id"], referencedColumnNames: ["id"],
@ -113,20 +143,31 @@ export class ProtocolTables1728563204766 implements MigrationInterface {
onUpdate: "RESTRICT", 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<void> { public async down(queryRunner: QueryRunner): Promise<void> {
const tableProtocolVotings = await queryRunner.getTable("protocol_votings"); const tableProtocolVotings = await queryRunner.getTable("protocol_voting");
const foreignKeyProtocolVotings = tableProtocolVotings.foreignKeys.find( const foreignKeyProtocolVotings = tableProtocolVotings.foreignKeys.find(
(fk) => fk.columnNames.indexOf("protocolId") !== -1 (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( const foreignKeyProtocolDecisions = tableProtocolDecisions.foreignKeys.find(
(fk) => fk.columnNames.indexOf("protocolId") !== -1 (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 tableProtocolAgenda = await queryRunner.getTable("protocol_agenda");
const foreignKeyProtocolAgenda = tableProtocolAgenda.foreignKeys.find( const foreignKeyProtocolAgenda = tableProtocolAgenda.foreignKeys.find(
@ -146,9 +187,17 @@ export class ProtocolTables1728563204766 implements MigrationInterface {
); );
await queryRunner.dropForeignKey("protocol_presence", foreignKeyProtocolPresence_member); 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_presence");
await queryRunner.dropTable("protocol_decisions"); await queryRunner.dropTable("protocol_decision");
await queryRunner.dropTable("protocol_agenda"); await queryRunner.dropTable("protocol_agenda");
await queryRunner.dropTable("protocol");
} }
} }