MalukuCitySeeder.js 1.3 KB

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