2020-07-29 20:56:03 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const faker = require ('faker');
|
2020-07-31 19:37:30 +02:00
|
|
|
const sn = require ('simplex-noise');
|
2020-07-29 20:56:03 +02:00
|
|
|
|
2020-08-16 11:48:06 +02:00
|
|
|
const apps = [];
|
|
|
|
|
|
|
|
async function create_app (knex) {
|
|
|
|
const [ id ] = await knex ('app')
|
|
|
|
.insert (
|
|
|
|
{ name: faker.random.word () }
|
|
|
|
);
|
|
|
|
apps.push (id);
|
|
|
|
}
|
|
|
|
|
2020-07-31 19:37:30 +02:00
|
|
|
function create_log (index, simplex) {
|
2020-07-30 18:39:37 +02:00
|
|
|
const data = {
|
|
|
|
num1: faker.random.number (),
|
2020-07-31 19:37:30 +02:00
|
|
|
num2: simplex.noise2D (index * 0.1, 0),
|
|
|
|
num3: simplex.noise2D (index * 0.1, 1000)
|
2020-07-30 18:39:37 +02:00
|
|
|
};
|
2020-07-29 20:56:03 +02:00
|
|
|
return {
|
2020-08-16 11:48:06 +02:00
|
|
|
app_id: faker.random.arrayElement (apps),
|
2020-07-29 20:56:03 +02:00
|
|
|
message: faker.random.words (),
|
2020-07-30 18:39:37 +02:00
|
|
|
data: JSON.stringify (data),
|
2020-07-29 20:56:03 +02:00
|
|
|
timestamp: faker.date.recent ()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async function seed (knex) {
|
2020-08-16 11:48:06 +02:00
|
|
|
await knex ('log')
|
|
|
|
.del ();
|
|
|
|
await knex ('app')
|
|
|
|
.del ();
|
|
|
|
|
2020-08-15 15:19:52 +02:00
|
|
|
// eslint-disable-next-line no-console
|
2020-07-29 20:56:03 +02:00
|
|
|
console.log ('creating seeds');
|
2020-08-16 11:48:06 +02:00
|
|
|
for (let i = 0; i < 5; i++)
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
|
|
|
await create_app (knex);
|
|
|
|
|
2020-07-31 19:37:30 +02:00
|
|
|
const simplex = (new sn);
|
2020-07-30 22:24:07 +02:00
|
|
|
const log = (Array (20))
|
2020-07-30 18:39:37 +02:00
|
|
|
.fill (() => null)
|
2020-07-31 19:37:30 +02:00
|
|
|
.map ((a, index) => create_log (index, simplex));
|
2020-07-30 18:39:37 +02:00
|
|
|
|
|
|
|
await knex.batchInsert ('log', log, 10);
|
2020-07-29 20:56:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { seed };
|