You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031
  1. const mock = require('../data-generator/mock')
  2. const fs = require('fs')
  3. const dataSort = require('../dataSort')
  4. const { batchSize, ignore } = require('../data-generator/config.json')
  5. let profiles = []
  6. const generatedDataPath = './db/generated'
  7. let fileNames = fs.readdirSync(generatedDataPath)
  8. for (let name of fileNames) {
  9. const data = require(`../generated/${name}`)
  10. if (name[0] == '_') {
  11. profiles = [...profiles, ...data.profiles]
  12. }
  13. }
  14. profiles = dataSort(profiles, 'profile_id').filter(
  15. profile => !ignore.includes(profile.profile_id),
  16. )
  17. exports.seed = async knex => {
  18. await knex('profiles').del()
  19. let profilesToPush = []
  20. let len = profiles.length
  21. for (let i = 1; i <= len; i += 1) {
  22. profilesToPush.push(profiles.shift())
  23. if (i % batchSize === 0 || i > profiles.length) {
  24. await knex('profiles').insert(profilesToPush)
  25. profilesToPush = []
  26. }
  27. }
  28. }