MalukuUtaraCitySeeder.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const prisma = require('../../../src/prisma/PrismaClient.js');
  2. const timeLocal = require('../../../src/utils/TimeLocal.js')
  3. const cityNames = [
  4. 'Kabupaten Halmahera Barat',
  5. 'Kabupaten Halmahera Tengah',
  6. 'Kabupaten Halmahera Timur',
  7. 'Kabupaten Halmahera Selatan',
  8. 'Kabupaten Halmahera Utara',
  9. 'Kabupaten Kepulauan Sula',
  10. 'Kabupaten Pulau Morotai',
  11. 'Kabupaten Pulau Taliabu',
  12. 'Kota Ternate',
  13. 'Kota Tidore Kepulauan'
  14. // 10
  15. ];
  16. exports.seedMalukuUtaraCities = async () => {
  17. const province = await prisma.province.findFirst({
  18. where: { name: 'Maluku Utara' },
  19. });
  20. if (!province) {
  21. console.error('❌ Province Maluku Utara not found. Seed it first.');
  22. return;
  23. }
  24. for (const name of cityNames) {
  25. await prisma.city.upsert({
  26. where: {
  27. name_province_id: {
  28. name,
  29. province_id: province.id,
  30. },
  31. },
  32. update: {
  33. updatedAt: timeLocal.now().toDate()
  34. },
  35. create: {
  36. name,
  37. province_id: province.id,
  38. createdAt: timeLocal.now().toDate()
  39. },
  40. });
  41. }
  42. console.log('✅ Maluku Utara City seeded!.');
  43. };