PapuaCitySeeder.ts 2.4 KB

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