fixed bug where the migrations table was deleted every time

This commit is contained in:
Ulf Gebhardt 2021-08-23 00:14:27 +02:00
parent e8d6e871c4
commit f1ed748983
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD

View File

@ -6,7 +6,7 @@
* creating, deleting, renaming Databases. * creating, deleting, renaming Databases.
*/ */
import { createConnection } from 'mysql2/promise' import { createConnection, RowDataPacket } from 'mysql2/promise'
import CONFIG from './config' import CONFIG from './config'
export default async (): Promise<void> => { export default async (): Promise<void> => {
@ -26,10 +26,10 @@ export default async (): Promise<void> => {
DEFAULT COLLATE utf8mb4_unicode_ci;`) DEFAULT COLLATE utf8mb4_unicode_ci;`)
// Check if old migration table is present, delete if needed // Check if old migration table is present, delete if needed
const result = await con.query( const [rows] = await con.query(
`SHOW COLUMNS FROM \`${CONFIG.DB_DATABASE}\`.\`migrations\` LIKE 'db_version';`, `SHOW COLUMNS FROM \`${CONFIG.DB_DATABASE}\`.\`migrations\` LIKE 'db_version';`,
) )
if (result.length > 0) { if ((<RowDataPacket>rows).length > 0) {
await con.query(`DROP TABLE \`${CONFIG.DB_DATABASE}\`.\`migrations\``) await con.query(`DROP TABLE \`${CONFIG.DB_DATABASE}\`.\`migrations\``)
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('Found and dropped old migrations table') console.log('Found and dropped old migrations table')