PapuaCitySeeder.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const prisma = require('../../../src/prisma/PrismaClient.js');
  2. const timeLocal = require('../../../src/utils/TimeLocal.js')
  3. const cityNames = [
  4. 'Kabupaten Biak Numfor',
  5. 'Kabupaten Jayapura',
  6. 'Kabupaten Keerom',
  7. 'Kabupaten Kepulauan Yapen',
  8. 'Kabupaten Mamberamo Raya',
  9. 'Kabupaten Sarmi',
  10. 'Kabupaten Supiori',
  11. 'Kabupaten Waropen',
  12. 'Kota Jayapura'
  13. // 9
  14. ];
  15. exports.seedPapuaCities = async () => {
  16. const province = await prisma.province.findFirst({
  17. where: { name: 'Papua' },
  18. });
  19. if (!province) {
  20. console.error('❌ Province Papua not found. Seed it first.');
  21. return;
  22. }
  23. for (const name of cityNames) {
  24. await prisma.city.upsert({
  25. where: {
  26. name_province_id: {
  27. name,
  28. province_id: province.id,
  29. },
  30. },
  31. update: { updatedAt: timeLocal.now().toDate() },
  32. create: {
  33. name,
  34. province_id: province.id,
  35. createdAt: timeLocal.now().toDate()
  36. },
  37. });
  38. }
  39. console.log('✅ Papua City seeded!.');
  40. };