KepulauanRiauCitySeeder.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 Bintan',
  5. 'Kabupaten Karimun',
  6. 'Kabupaten Kepulauan Anambas',
  7. 'Kabupaten Lingga',
  8. 'Kabupaten Natuna',
  9. 'Kota Batam',
  10. 'Kota Tanjung Pinang'
  11. // 7
  12. ];
  13. exports.seedKepulauanRiauCities = async () => {
  14. const province = await prisma.province.findFirst({
  15. where: { name: 'Kepulauan Riau' },
  16. });
  17. if (!province) {
  18. console.error('❌ Province Kepulauan Riau not found. Seed it first.');
  19. return;
  20. }
  21. for (const name of cityNames) {
  22. await prisma.city.upsert({
  23. where: {
  24. name_province_id: {
  25. name,
  26. province_id: province.id,
  27. },
  28. },
  29. update: {
  30. updatedAt: timeLocal.now().toDate()
  31. },
  32. create: {
  33. name,
  34. province_id: province.id,
  35. createdAt: timeLocal.now().toDate()
  36. },
  37. });
  38. }
  39. console.log('✅ Kepulauan Riau City seeded!.');
  40. };