seed.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { PrismaClient, TeamMemberRole } from '@prisma/client';
  2. const prisma = new PrismaClient();
  3. const noOfUsers = 600000;
  4. const getAllUser = async () => {
  5. const users = await prisma.user.findMany();
  6. return users;
  7. };
  8. const createUsers = async () => {
  9. for (let i = 1; i <= noOfUsers; i++) {
  10. try {
  11. await prisma.user.create({
  12. data: {
  13. email: `${i}@gmail.com`,
  14. },
  15. });
  16. } catch (_) {}
  17. }
  18. };
  19. const createTeams = async () => {
  20. const users = await getAllUser();
  21. for (let i = 0; i < users.length; i++) {
  22. try {
  23. await prisma.team.create({
  24. data: {
  25. name: `Team ${i + 1}`,
  26. members: {
  27. create: {
  28. userUid: users[i].uid,
  29. role: TeamMemberRole.OWNER,
  30. },
  31. },
  32. },
  33. });
  34. } catch (_) {}
  35. }
  36. };
  37. async function main() {
  38. console.log('Seeding...');
  39. await createUsers();
  40. await createTeams();
  41. }
  42. main()
  43. .then(async () => {
  44. await prisma.$disconnect();
  45. })
  46. .catch(async (e) => {
  47. console.error(e);
  48. await prisma.$disconnect();
  49. process.exit(1);
  50. });