fixed build js up/down/reset commands

started to do some more prepare stuff
This commit is contained in:
Ulf Gebhardt 2021-08-23 00:00:35 +02:00
parent 9660a883c3
commit d480cadf93
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
2 changed files with 19 additions and 4 deletions

View File

@ -10,9 +10,9 @@
"scripts": { "scripts": {
"build": "tsc --build", "build": "tsc --build",
"clean": "tsc --build --clean", "clean": "tsc --build --clean",
"up": "node build/src/index.js up", "up": "cd build && node src/index.js up",
"down": "node build/src/index.js down", "down": "cd build && node src/index.js down",
"reset": "node build/src/index.js reset", "reset": "cd build && node src/index.js reset",
"dev_up": "nodemon -w ./ --ext ts --exec ts-node src/index.ts up", "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_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", "dev_reset": "nodemon -w ./ --ext ts --exec ts-node src/index.ts reset",

View File

@ -9,7 +9,7 @@
import { createConnection } from 'mysql' import { createConnection } from 'mysql'
import CONFIG from './config' import CONFIG from './config'
export default async () => { export default async (): Promise<void> => {
const con = createConnection({ const con = createConnection({
host: CONFIG.DB_HOST, host: CONFIG.DB_HOST,
port: CONFIG.DB_PORT, port: CONFIG.DB_PORT,
@ -24,4 +24,19 @@ export default async () => {
CREATE DATABASE IF NOT EXISTS ${CONFIG.DB_DATABASE} CREATE DATABASE IF NOT EXISTS ${CONFIG.DB_DATABASE}
DEFAULT CHARACTER SET utf8mb4 DEFAULT CHARACTER SET utf8mb4
DEFAULT COLLATE utf8mb4_unicode_ci;`) 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()
} }