20200201071649-UserSeeder.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. const bcrypt = require("bcrypt");
  3. const saltRounds = 10;
  4. const names = ["林", "李", "郭", "鄭", "楊", "黃", "陳", "連", "周", "何"];
  5. async function getUserData(name) {
  6. const password = await bcrypt.hashSync("test", saltRounds);
  7. return {
  8. password,
  9. name,
  10. permission: 1
  11. };
  12. }
  13. module.exports = {
  14. up: async (queryInterface, Sequelize) => {
  15. const getUserPromises = Array.from(Array(10).keys()).map(index =>
  16. getUserData(names[index])
  17. );
  18. const users = await Promise.all(getUserPromises);
  19. return queryInterface.bulkInsert("users", users);
  20. /*
  21. Add altering commands here.
  22. Return a promise to correctly handle asynchronicity.
  23. Example:
  24. return queryInterface.bulkInsert('People', [{
  25. name: 'John Doe',
  26. isBetaMember: false
  27. }], {});
  28. */
  29. },
  30. down: (queryInterface, Sequelize) => {
  31. /*
  32. Add reverting commands here.
  33. Return a promise to correctly handle asynchronicity.
  34. Example:
  35. return queryInterface.bulkDelete('People', null, {});
  36. */
  37. }
  38. };