| 12345678910111213141516171819202122232425262728293031 |
- const mock = require('../data-generator/mock')
- const fs = require('fs')
- const dataSort = require('../dataSort')
- const { batchSize, ignore } = require('../data-generator/config.json')
-
- let profiles = []
- const generatedDataPath = './db/generated'
- let fileNames = fs.readdirSync(generatedDataPath)
- for (let name of fileNames) {
- const data = require(`../generated/${name}`)
- if (name[0] == '_') {
- profiles = [...profiles, ...data.profiles]
- }
- }
-
- profiles = dataSort(profiles, 'profile_id').filter(
- profile => !ignore.includes(profile.profile_id),
- )
-
- exports.seed = async knex => {
- await knex('profiles').del()
- let profilesToPush = []
- let len = profiles.length
- for (let i = 1; i <= len; i += 1) {
- profilesToPush.push(profiles.shift())
- if (i % batchSize === 0 || i > profiles.length) {
- await knex('profiles').insert(profilesToPush)
- profilesToPush = []
- }
- }
- }
|