/* * Copyright (C) Sapphirecode - All Rights Reserved * This file is part of appreports which is released under GPL-3.0-or-later. * See file 'LICENSE' for full license details. * Created by Timo Hocker , August 2020 */ 'use strict'; const faker = require ('faker'); let last_t = 0; let last_h = 0; function create_log (timestamp) { last_t = faker.random.number (2) + 22; last_h = faker.random.number (10) + 38; const data = { light: faker.random.number (10), temperature: last_t, humidity: last_h }; return { app_id: 1, message: faker.random.words (), data: JSON.stringify (data), timestamp }; } async function seed (knex) { await knex ('log') .del (); // eslint-disable-next-line no-console console.log ('creating seeds'); const log = (Array (10000)) .fill (() => null) .map (() => faker.date.recent (60)) .sort () .map ((t) => create_log (t)); await knex.batchInsert ('log', log, 10); } module.exports = { seed };