SulawesiBaratCitySeeder.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const prisma = require('../../../src/prisma/PrismaClient.js');
  2. const timeLocal = require('../../../src/utils/TimeLocal.js')
  3. const cityNames = [
  4. 'Kabupaten Majene',
  5. 'Kabupaten Mamasa',
  6. 'Kabupaten Mamuju',
  7. 'Kabupaten Mamuju Tengah',
  8. 'Kabupaten Pasangkayu',
  9. 'Kabupaten Polewali Mandar'
  10. // 6
  11. ];
  12. exports.seedSulawesiBaratCities = async () => {
  13. const province = await prisma.province.findFirst({
  14. where: { name: 'Sulawesi Barat' },
  15. });
  16. if (!province) {
  17. console.error('❌ Province Sulawesi Barat not found. Seed it first.');
  18. return;
  19. }
  20. for (const name of cityNames) {
  21. await prisma.city.upsert({
  22. where: {
  23. name_province_id: {
  24. name,
  25. province_id: province.id,
  26. },
  27. },
  28. update: { updatedAt: timeLocal.now().toDate() },
  29. create: {
  30. name,
  31. province_id: province.id,
  32. createdAt: timeLocal.now().toDate()
  33. },
  34. });
  35. }
  36. console.log('✅ Sulawesi Barat City seeded!.');
  37. };