2020-04-11 18:57:35 +00:00
|
|
|
const db = require('../db/db')
|
2020-04-11 18:26:34 +00:00
|
|
|
const request = require('request')
|
|
|
|
const path = require('path')
|
|
|
|
const dotenv = require('dotenv').config({path: path.join(__dirname, '../../.env')})
|
|
|
|
|
|
|
|
// The URL from which to export production data
|
|
|
|
const url = 'https://jasonsplant.glitch.me/exportall'
|
|
|
|
|
|
|
|
// Get data from the production server
|
|
|
|
request({
|
|
|
|
url,
|
|
|
|
headers: {
|
|
|
|
'export-key': process.env.SECRET
|
|
|
|
},
|
|
|
|
json: true
|
|
|
|
}, (error, {body}) => {
|
|
|
|
if (error) return console.log(error)
|
|
|
|
|
|
|
|
console.log(body.length + ' items retrieved')
|
|
|
|
|
|
|
|
// Remove existing database items
|
2020-04-11 18:57:35 +00:00
|
|
|
db.Readings.destroy({truncate: true})
|
2020-04-11 18:26:34 +00:00
|
|
|
|
|
|
|
// Add new data to the database
|
2020-04-11 18:57:35 +00:00
|
|
|
db.Readings.bulkCreate(body)
|
2020-04-11 18:26:34 +00:00
|
|
|
});
|