007-clients.js 884 B

123456789101112131415161718192021222324252627282930
  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_clients";
  6. module.exports = {
  7. up: async (queryInterface, Sequelize) => {
  8. faker.seed(seedValue);
  9. const uniqueNames = generateUniqueList(
  10. seedRowCounts.clients,
  11. () => `${faker.name.firstName()} ${faker.name.lastName()}`
  12. );
  13. const data = uniqueNames.map((name, index) => ({
  14. id: index + 1,
  15. name,
  16. email: `${name.split(" ").join(".")}@example.com`,
  17. address: `${faker.address.streetAddress()}`,
  18. phone: `${parseInt(faker.phone.phoneNumber)}`,
  19. }));
  20. await queryInterface.bulkInsert(TABLE_NAME, data, {});
  21. },
  22. down: async (queryInterface, Sequelize) => {
  23. await queryInterface.bulkDelete(TABLE_NAME, null, {});
  24. },
  25. };