From 6d3e74aac9b7c5b79689b7ca8908b6a8d7fc931b Mon Sep 17 00:00:00 2001 From: JayWll Date: Mon, 13 Apr 2020 10:01:40 -0600 Subject: [PATCH] Adding sync() commands to database scripts --- nodeapp/utils/import.js | 3 +++ nodeapp/utils/init-settings.js | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/nodeapp/utils/import.js b/nodeapp/utils/import.js index 975a158..0413359 100644 --- a/nodeapp/utils/import.js +++ b/nodeapp/utils/import.js @@ -19,6 +19,9 @@ request({ console.log(response.body.length + ' items retrieved') + // Sync the database table + await db.Settings.sync() + // Remove existing database items await db.Readings.destroy({truncate: true}) diff --git a/nodeapp/utils/init-settings.js b/nodeapp/utils/init-settings.js index b49ce69..5c13409 100644 --- a/nodeapp/utils/init-settings.js +++ b/nodeapp/utils/init-settings.js @@ -2,11 +2,13 @@ const db = require('../db/db') const path = require('path') require('dotenv').config({path: path.join(__dirname, '../../.env')}) -// Remove all previous settings -db.Settings.destroy({truncate: true}) +db.Settings.sync().then(() => { + // Remove all previous settings + db.Settings.destroy({truncate: true}) -// Create settings -db.Settings.create({ key: 'low-trigger', value: 100 }) -db.Settings.create({ key: 'high-trigger', value: 900 }) -db.Settings.create({ key: 'low', value: false }) -db.Settings.create({ key: 'alert', value: false }) + // Create settings + db.Settings.create({ key: 'low-trigger', value: 100 }) + db.Settings.create({ key: 'high-trigger', value: 900 }) + db.Settings.create({ key: 'low', value: false }) + db.Settings.create({ key: 'alert', value: false }) +})