2025-01-29 18:10:41 +01:00
|
|
|
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
|
|
|
import BackupHelper from "../helpers/backupHelper";
|
2025-01-30 15:58:34 +01:00
|
|
|
import { getTypeByORM } from "./ormHelper";
|
2025-01-29 18:10:41 +01:00
|
|
|
import InternalException from "../exceptions/internalException";
|
|
|
|
|
|
|
|
export class BackupAndResetDatabase1738166124200 implements MigrationInterface {
|
|
|
|
name = "BackupAndResetDatabase1738166124200";
|
|
|
|
|
|
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
2025-01-30 15:58:34 +01:00
|
|
|
if ((await queryRunner.hasTable("user")) && !(await queryRunner.hasTable("salutation"))) {
|
2025-01-31 11:25:00 +01:00
|
|
|
throw new InternalException(
|
|
|
|
"Cannot update due to skiped version. Update to v1.2.2 Version first to prevent data loss and get access to the newer Versions."
|
|
|
|
);
|
2025-01-30 15:58:34 +01:00
|
|
|
}
|
2025-01-29 18:10:41 +01:00
|
|
|
|
2025-01-30 15:58:34 +01:00
|
|
|
if (await queryRunner.hasTable("user")) {
|
|
|
|
await BackupHelper.createBackup({ collectIds: false });
|
|
|
|
}
|
2025-01-29 18:10:41 +01:00
|
|
|
await queryRunner.clearDatabase();
|
|
|
|
|
|
|
|
await queryRunner.createTable(
|
|
|
|
new Table({
|
|
|
|
name: "migrations",
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
name: "id",
|
|
|
|
type: getTypeByORM("int"),
|
|
|
|
isPrimary: true,
|
|
|
|
isGenerated: true,
|
|
|
|
generationStrategy: "increment",
|
|
|
|
},
|
|
|
|
{ name: "timestamp", type: getTypeByORM("bigint"), isNullable: false },
|
|
|
|
{ name: "name", type: getTypeByORM("varchar"), length: "255", isNullable: false },
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
await queryRunner.createTable(
|
|
|
|
new Table({
|
|
|
|
name: "typeorm_metadata",
|
|
|
|
columns: [
|
|
|
|
{ name: "type", type: getTypeByORM("varchar"), length: "255", isNullable: false },
|
|
|
|
{ name: "database", type: getTypeByORM("varchar"), length: "255", isNullable: true, default: null },
|
|
|
|
{ name: "schema", type: getTypeByORM("varchar"), length: "255", isNullable: true, default: null },
|
|
|
|
{ name: "table", type: getTypeByORM("varchar"), length: "255", isNullable: true, default: null },
|
|
|
|
{ name: "name", type: getTypeByORM("varchar"), length: "255", isNullable: true, default: null },
|
|
|
|
{ name: "value", type: getTypeByORM("text"), length: "255", isNullable: true, default: null },
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {}
|
|
|
|
}
|