PapuaBaratCitySeeder.ts 2.5 KB

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