migrate schema to postgres only
This commit is contained in:
parent
c849b8eb18
commit
97ffae009b
33 changed files with 363 additions and 1238 deletions
54
src/migrations/1749296262915-BackupAndResetDatabase.ts
Normal file
54
src/migrations/1749296262915-BackupAndResetDatabase.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import BackupHelper from "../helpers/backupHelper";
|
||||
import { getTypeByORM, isIncrementPrimary, getDefaultByORM } from "./ormHelper";
|
||||
|
||||
export class BackupAndResetDatabase1749296262915 implements MigrationInterface {
|
||||
name = "BackupAndResetDatabase1749296262915";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
let migrations = await queryRunner.query("SELECT name FROM migrations");
|
||||
if (
|
||||
(await queryRunner.hasTable("user")) &&
|
||||
migrations.findIndex((m: any) => m.name == "MemberExtendData1748953828644") == -1
|
||||
) {
|
||||
throw new InternalException(
|
||||
"Cannot update due to skiped version. Update to v1.6.0 Version first to prevent data loss and get access to the newer Versions."
|
||||
);
|
||||
}
|
||||
|
||||
if (await queryRunner.hasTable("user")) {
|
||||
await BackupHelper.createBackup({ collectIds: false });
|
||||
}
|
||||
await queryRunner.clearDatabase();
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "migrations",
|
||||
columns: [
|
||||
{ name: "id", ...getTypeByORM("int"), ...isIncrementPrimary },
|
||||
{ name: "timestamp", ...getTypeByORM("bigint") },
|
||||
{ name: "name", ...getTypeByORM("varchar") },
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "typeorm_metadata",
|
||||
columns: [
|
||||
{ name: "type", ...getTypeByORM("varchar") },
|
||||
{ name: "database", ...getTypeByORM("varchar", true), default: getDefaultByORM("null") },
|
||||
{ name: "schema", ...getTypeByORM("varchar", true), default: getDefaultByORM("null") },
|
||||
{ name: "table", ...getTypeByORM("varchar", true), default: getDefaultByORM("null") },
|
||||
{ name: "name", ...getTypeByORM("varchar", true), default: getDefaultByORM("null") },
|
||||
{ name: "value", ...getTypeByORM("text", true), default: getDefaultByORM("null") },
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue