2020-04-25 21:30:06 +00:00
|
|
|
const db = require('../src/db')
|
2020-04-11 18:26:34 +00:00
|
|
|
const request = require('request')
|
|
|
|
const path = require('path')
|
2020-04-11 19:00:00 +00:00
|
|
|
require('dotenv').config({path: path.join(__dirname, '../../.env')})
|
2020-04-11 18:26:34 +00:00
|
|
|
|
|
|
|
// The URL from which to export production data
|
2020-04-25 21:30:06 +00:00
|
|
|
const readingsurl = 'https://jasonsplant.glitch.me/exportall'
|
|
|
|
const settingsurl = 'https://jasonsplant.glitch.me/showsettings'
|
2020-04-11 18:26:34 +00:00
|
|
|
|
2020-04-25 21:30:06 +00:00
|
|
|
// Get readings from the production server
|
2020-04-11 18:26:34 +00:00
|
|
|
request({
|
2020-04-25 21:30:06 +00:00
|
|
|
url: readingsurl,
|
2020-04-11 18:26:34 +00:00
|
|
|
headers: {
|
|
|
|
'export-key': process.env.SECRET
|
|
|
|
},
|
|
|
|
json: true
|
2020-04-11 19:34:32 +00:00
|
|
|
}, async(error, response) => {
|
2020-04-11 18:26:34 +00:00
|
|
|
if (error) return console.log(error)
|
2020-04-11 19:34:32 +00:00
|
|
|
if (response.statusCode != 200) return console.log('Unsuccessful, as indicated by HTTP status')
|
2020-04-11 18:26:34 +00:00
|
|
|
|
2020-04-25 21:30:06 +00:00
|
|
|
console.log(response.body.length + ' readings retrieved')
|
2020-04-13 16:01:40 +00:00
|
|
|
|
2020-04-11 18:26:34 +00:00
|
|
|
// Remove existing database items
|
2020-04-11 19:34:32 +00:00
|
|
|
await db.Readings.destroy({truncate: true})
|
2020-04-11 18:26:34 +00:00
|
|
|
|
|
|
|
// Add new data to the database
|
2020-04-11 19:34:32 +00:00
|
|
|
await db.Readings.bulkCreate(response.body)
|
2020-04-11 18:26:34 +00:00
|
|
|
});
|
2020-04-25 21:30:06 +00:00
|
|
|
|
|
|
|
// Get settings from the production server
|
|
|
|
request({
|
|
|
|
url: settingsurl,
|
|
|
|
headers: {
|
|
|
|
'export-key': process.env.SECRET
|
|
|
|
},
|
|
|
|
json: true
|
|
|
|
}, async(error, response) => {
|
|
|
|
if (error) return console.log(error)
|
|
|
|
if (response.statusCode != 200) return console.log('Unsuccessful, as indicated by HTTP status')
|
|
|
|
|
|
|
|
console.log(response.body.length + ' settings retrieved')
|
|
|
|
|
|
|
|
// Remove existing database items
|
|
|
|
await db.Settings.destroy({truncate: true})
|
|
|
|
|
|
|
|
// Add new data to the database
|
|
|
|
await db.Settings.bulkCreate(response.body)
|
|
|
|
});
|