SulawesiBaratCitySeeder.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import prisma from '../../../src/prisma/PrismaClient';
  2. import { now } from '../../../src/utils/TimeLocal';
  3. const cityNames: string[] = [
  4. 'Kabupaten Majene',
  5. 'Kabupaten Mamasa',
  6. 'Kabupaten Mamuju',
  7. 'Kabupaten Mamuju Tengah',
  8. 'Kabupaten Pasangkayu',
  9. 'Kabupaten Polewali Mandar'
  10. ];
  11. export const seedSulawesiBaratCities = async (): Promise<void> => {
  12. const province = await prisma.province.findFirst({
  13. where: { name: 'Sulawesi Barat' },
  14. });
  15. if (!province) {
  16. console.error('❌ Province Sulawesi Barat not found. Seed it first.');
  17. return;
  18. }
  19. for (const name of cityNames) {
  20. await prisma.city.upsert({
  21. where: {
  22. // Pastikan ada @@unique([name, province_id]) di model City di schema.prisma
  23. name_province_id: {
  24. name,
  25. province_id: province.id,
  26. },
  27. },
  28. update: {
  29. updatedAt: now().toDate(),
  30. },
  31. create: {
  32. name,
  33. province_id: province.id,
  34. createdAt: now().toDate(),
  35. },
  36. });
  37. }
  38. console.log('✅ Sulawesi Barat City seeded!.');
  39. };
  40. // const prisma = require('../../../src/prisma/PrismaClient.js');
  41. // const timeLocal = require('../../../src/utils/TimeLocal.js')
  42. // const cityNames = [
  43. // 'Kabupaten Majene',
  44. // 'Kabupaten Mamasa',
  45. // 'Kabupaten Mamuju',
  46. // 'Kabupaten Mamuju Tengah',
  47. // 'Kabupaten Pasangkayu',
  48. // 'Kabupaten Polewali Mandar'
  49. // // 6
  50. // ];
  51. // exports.seedSulawesiBaratCities = async () => {
  52. // const province = await prisma.province.findFirst({
  53. // where: { name: 'Sulawesi Barat' },
  54. // });
  55. // if (!province) {
  56. // console.error('❌ Province Sulawesi Barat not found. Seed it first.');
  57. // return;
  58. // }
  59. // for (const name of cityNames) {
  60. // await prisma.city.upsert({
  61. // where: {
  62. // name_province_id: {
  63. // name,
  64. // province_id: province.id,
  65. // },
  66. // },
  67. // update: { updatedAt: timeLocal.now().toDate() },
  68. // create: {
  69. // name,
  70. // province_id: province.id,
  71. // createdAt: timeLocal.now().toDate()
  72. // },
  73. // });
  74. // }
  75. // console.log('✅ Sulawesi Barat City seeded!.');
  76. // };