diff --git a/database/package.json b/database/package.json index ced0054d1..168794760 100644 --- a/database/package.json +++ b/database/package.json @@ -10,9 +10,9 @@ "scripts": { "build": "tsc --build", "clean": "tsc --build --clean", - "up": "node build/src/index.js up", - "down": "node build/src/index.js down", - "reset": "node build/src/index.js reset", + "up": "cd build && node src/index.js up", + "down": "cd build && node src/index.js down", + "reset": "cd build && node src/index.js reset", "dev_up": "nodemon -w ./ --ext ts --exec ts-node src/index.ts up", "dev_down": "nodemon -w ./ --ext ts --exec ts-node src/index.ts down", "dev_reset": "nodemon -w ./ --ext ts --exec ts-node src/index.ts reset", diff --git a/database/src/prepare.ts b/database/src/prepare.ts index 8ab0e8e84..174639f1a 100644 --- a/database/src/prepare.ts +++ b/database/src/prepare.ts @@ -9,7 +9,7 @@ import { createConnection } from 'mysql' import CONFIG from './config' -export default async () => { +export default async (): Promise => { const con = createConnection({ host: CONFIG.DB_HOST, port: CONFIG.DB_PORT, @@ -24,4 +24,19 @@ export default async () => { CREATE DATABASE IF NOT EXISTS ${CONFIG.DB_DATABASE} DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;`) + + // Check if old migration table is present, delete if needed + await con.query( + `SHOW COLUMNS FROM \`${CONFIG.DB_DATABASE}\`.\`migrations\` LIKE 'version';`, + (err, result /* , fields */) => { + if (err) throw err + if (result.length > 0) { + 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() }