const aspects = require('../generated/prescore_matrix.json') exports.seed = function (knex) { // Deletes ALL existing entries return knex('prescored_aspects') .truncate() .then(function () { let rowCount = 1 const makeRow = scores => { scoreMap = {} scores.forEach((score, i) => { scoreMap['aspect_id'] = rowCount scoreMap[i + 1] = score }) return scoreMap } const rows = [] Object.values(aspects).forEach(rowOfScores => { if(Array.isArray(rowOfScores)) { const row = makeRow(rowOfScores) rows.push(row) rowCount++ } }) // Inserts seed entries return knex('prescored_aspects').insert(rows) }) }