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.

02-profiles.js 802B

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