006-robotFeatures.js 965 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. const faker = require("faker");
  3. const { seedValue, seedRowCounts, features } = require("../src/config/seeders");
  4. const TABLE_NAME = "sl_robot_features";
  5. module.exports = {
  6. up: async (queryInterface, Sequelize) => {
  7. faker.seed(seedValue);
  8. const data = [];
  9. const allFeaturesIds = features.map((_, index) => index + 1);
  10. for (let robotId = 1; robotId <= seedRowCounts.robots; robotId += 1) {
  11. const randomFeaturesIds = faker.helpers.shuffle(allFeaturesIds);
  12. const size = faker.random.number({ min: 1, max: seedRowCounts.maxFeaturesPerRobot });
  13. const uniqueFeaturesIds = randomFeaturesIds.slice(0, size);
  14. uniqueFeaturesIds.forEach((featureId) => {
  15. data.push({ id: data.length + 1, robotId, featureId });
  16. });
  17. }
  18. await queryInterface.bulkInsert(TABLE_NAME, data, {});
  19. },
  20. down: async (queryInterface, Sequelize) => {
  21. await queryInterface.bulkDelete(TABLE_NAME, null, {});
  22. },
  23. };