From ab98f3b6f892dd9cac8263ce9d639b4d35098716 Mon Sep 17 00:00:00 2001 From: lesion Date: Wed, 26 Jun 2019 16:15:25 +0200 Subject: [PATCH] check non empty db during setup --- server/firstrun.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/firstrun.js b/server/firstrun.js index c1c2e0ff..264032c4 100644 --- a/server/firstrun.js +++ b/server/firstrun.js @@ -18,15 +18,18 @@ module.exports = { consola.info(`Save configuration into ${config_path}`) fs.writeFileSync(config_path, JSON.stringify(config, null, 2)) - // sync db (TODO, check if there's something in db and ask to backup) + // sync db const db = require('./api/models') try { - consola.info(`Create tables..`) - await db.sequelize.sync({force: true}) - } catch(e) { + await db.user.findAll() + consola.warning(`!WARNING! Non empty db!`) + return -1 + } catch(e) {} + + await db.sequelize.sync({force: true}).catch(e => { consola.error('Error creating tables', e) return -1 - } + }) // create admin user consola.info('Create admin user')