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.
*/
import { createConnection } from 'mysql2/promise'
import { createConnection, RowDataPacket } from 'mysql2/promise'
import CONFIG from './config'
export default async (): Promise<void> => {
@ -26,10 +26,10 @@ export default async (): Promise<void> => {
DEFAULT COLLATE utf8mb4_unicode_ci;`)
// 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';`,
)
if (result.length > 0) {
if ((<RowDataPacket>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')