GorontaloCitySeeder.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const prisma = require('../../../src/prisma/PrismaClient.js');
  2. const timeLocal = require('../../../src/utils/TimeLocal.js')
  3. const cityNames = [
  4. 'Kabupaten Boalemo',
  5. 'Kabupaten Bone Bolango',
  6. 'Kabupaten Gorontalo',
  7. 'Kabupaten Gorontalo Utara',
  8. 'Kabupaten Pohuwato',
  9. 'Kota Gorontalo'
  10. // 6
  11. ];
  12. exports.seedGorontaloCities = async () => {
  13. const province = await prisma.province.findFirst({
  14. where: { name: 'Gorontalo' },
  15. });
  16. if (!province) {
  17. console.error('❌ Province Gorontalo 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: {
  29. updatedAt: timeLocal.now().toDate()
  30. },
  31. create: {
  32. name,
  33. province_id: province.id,
  34. createdAt: timeLocal.now().toDate()
  35. },
  36. });
  37. }
  38. console.log('✅ Gorontalo City seeded!.');
  39. };