004-robotExperts.js 968 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. const faker = require("faker");
  3. const { generateUniqueList } = require("../seedersUtils");
  4. const { seedValue, seedRowCounts } = require("../src/config/seeders");
  5. const TABLE_NAME = "sl_robot_experts";
  6. module.exports = {
  7. up: async (queryInterface, Sequelize) => {
  8. faker.seed(seedValue);
  9. const data = [];
  10. for (let robotId = 1; robotId <= seedRowCounts.robots; robotId += 1) {
  11. const size = faker.random.number({ min: 1, max: seedRowCounts.maxExpertsPerRobot });
  12. const uniqueStaffMembersIds = generateUniqueList(size, () =>
  13. faker.random.number({ min: 1, max: seedRowCounts.staffMembers })
  14. );
  15. uniqueStaffMembersIds.forEach((staffMemberId) => {
  16. data.push({ id: data.length + 1, robotId, staffMemberId });
  17. });
  18. }
  19. await queryInterface.bulkInsert(TABLE_NAME, data, {});
  20. },
  21. down: async (queryInterface, Sequelize) => {
  22. await queryInterface.bulkDelete(TABLE_NAME, null, {});
  23. },
  24. };