From 622107a6f147bfb9772c66bb3cebd7f0dd9ebd73 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Fri, 17 May 2024 17:12:03 -0300 Subject: [PATCH] check if table exists and has items before running migration --- .../migrations/1715900413313-fix_repack_uploadDate.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/migrations/1715900413313-fix_repack_uploadDate.ts b/src/main/migrations/1715900413313-fix_repack_uploadDate.ts index 0f0b8966..37048cc3 100644 --- a/src/main/migrations/1715900413313-fix_repack_uploadDate.ts +++ b/src/main/migrations/1715900413313-fix_repack_uploadDate.ts @@ -7,6 +7,16 @@ import { In, MigrationInterface, QueryRunner, Table } from "typeorm"; export class FixRepackUploadDate1715900413313 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { + const existsTable = await queryRunner.query( + `SELECT name FROM sqlite_master WHERE type='table' AND name='repack';` + ); + + if (!existsTable.length) return; + + const repackCount = await queryRunner.manager.count(Repack); + + if (!repackCount) return; + await queryRunner.createTable( new Table({ name: "repack_temp",