KalimantanSelatanCitySeeder.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const prisma = require('../../../src/prisma/PrismaClient.js');
  2. const timeLocal = require('../../../src/utils/TimeLocal.js')
  3. const cityNames = [
  4. 'Kabupaten Balangan',
  5. 'Kabupaten Banjar',
  6. 'Kabupaten Barito Kuala',
  7. 'Kabupaten Hulu Sungai Selatan',
  8. 'Kabupaten Hulu Sungai Tengah',
  9. 'Kabupaten Hulu Sungai Utara',
  10. 'Kabupaten Kotabaru',
  11. 'Kabupaten Tabalong',
  12. 'Kabupaten Tanah Bumbu',
  13. 'Kabupaten Tanah Laut',
  14. 'Kabupaten Tapin',
  15. 'Kota Banjarbaru',
  16. 'Kota Banjarmasin'
  17. // 13
  18. ];
  19. exports.seedKalimantanSelatanCities = async () => {
  20. const province = await prisma.province.findFirst({
  21. where: { name: 'Kalimantan Selatan' },
  22. });
  23. if (!province) {
  24. console.error('❌ Province Kalimantan Selatan not found. Seed it first.');
  25. return;
  26. }
  27. for (const name of cityNames) {
  28. await prisma.city.upsert({
  29. where: {
  30. name_province_id: {
  31. name,
  32. province_id: province.id,
  33. },
  34. },
  35. update: {
  36. updatedAt: timeLocal.now().toDate()
  37. },
  38. create: {
  39. name,
  40. province_id: province.id,
  41. createdAt: timeLocal.now().toDate()
  42. },
  43. });
  44. }
  45. console.log('✅ Kalimantan Selatan City seeded!.');
  46. };