From d4b5872ef29867d25f2be04892efdc6b3bb813dd Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 23 Aug 2021 00:39:49 +0200 Subject: [PATCH] also check if migration table is present at all --- database/src/prepare.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/database/src/prepare.ts b/database/src/prepare.ts index 6fa723afd..440289aea 100644 --- a/database/src/prepare.ts +++ b/database/src/prepare.ts @@ -26,13 +26,16 @@ export default async (): Promise => { DEFAULT COLLATE utf8mb4_unicode_ci;`) // Check if old migration table is present, delete if needed - const [rows] = await con.query( - `SHOW COLUMNS FROM \`${CONFIG.DB_DATABASE}\`.\`migrations\` LIKE 'db_version';`, - ) + const [rows] = await con.query(`SHOW TABLES FROM \`${CONFIG.DB_DATABASE}\` LIKE 'migrations';`) if ((rows).length > 0) { - await con.query(`DROP TABLE \`${CONFIG.DB_DATABASE}\`.\`migrations\``) - // eslint-disable-next-line no-console - console.log('Found and dropped old migrations table') + const [rows] = await con.query( + `SHOW COLUMNS FROM \`${CONFIG.DB_DATABASE}\`.\`migrations\` LIKE 'db_version';`, + ) + if ((rows).length > 0) { + await con.query(`DROP TABLE \`${CONFIG.DB_DATABASE}\`.\`migrations\``) + // eslint-disable-next-line no-console + console.log('Found and dropped old migrations table') + } } await con.end()