split per app

This commit is contained in:
2020-08-16 11:48:06 +02:00
parent d3a19c953a
commit c5be16963d
12 changed files with 126 additions and 14 deletions

View File

@ -3,6 +3,16 @@
const faker = require ('faker');
const sn = require ('simplex-noise');
const apps = [];
async function create_app (knex) {
const [ id ] = await knex ('app')
.insert (
{ name: faker.random.word () }
);
apps.push (id);
}
function create_log (index, simplex) {
const data = {
num1: faker.random.number (),
@ -10,7 +20,7 @@ function create_log (index, simplex) {
num3: simplex.noise2D (index * 0.1, 1000)
};
return {
app: faker.random.word (),
app_id: faker.random.arrayElement (apps),
message: faker.random.words (),
data: JSON.stringify (data),
timestamp: faker.date.recent ()
@ -18,14 +28,21 @@ function create_log (index, simplex) {
}
async function seed (knex) {
await knex ('log')
.del ();
await knex ('app')
.del ();
// eslint-disable-next-line no-console
console.log ('creating seeds');
for (let i = 0; i < 5; i++)
// eslint-disable-next-line no-await-in-loop
await create_app (knex);
const simplex = (new sn);
const log = (Array (20))
.fill (() => null)
.map ((a, index) => create_log (index, simplex));
await knex ('log')
.del ();
await knex.batchInsert ('log', log, 10);
}