BantenCitySeeder.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import prisma from '../../../src/prisma/PrismaClient';
  2. import { now } from '../../../src/utils/TimeLocal';
  3. const cityNames: string[] = [
  4. 'Kabupaten Lebak',
  5. 'Kabupaten Pandeglang',
  6. 'Kabupaten Serang',
  7. 'Kabupaten Tangerang',
  8. 'Kota Cilegon',
  9. 'Kota Serang',
  10. 'Kota Tangerang',
  11. 'Kota Tangerang Selatan'
  12. ];
  13. export async function seedBantenCities(): Promise<void> {
  14. const province = await prisma.province.findFirst({
  15. where: { name: 'Banten' },
  16. });
  17. if (!province) {
  18. console.error('❌ Province Banten 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: now().toDate(),
  31. },
  32. create: {
  33. name,
  34. province_id: province.id,
  35. createdAt: now().toDate(),
  36. },
  37. });
  38. }
  39. console.log('✅ Banten City seeded!');
  40. }
  41. // const prisma = require('../../../src/prisma/PrismaClient.js');
  42. // const timeLocal = require('../../../src/utils/TimeLocal.js')
  43. // const cityNames = [
  44. // 'Kabupaten Lebak',
  45. // 'Kabupaten Pandeglang',
  46. // 'Kabupaten Serang',
  47. // 'Kabupaten Tangerang',
  48. // 'Kota Cilegon',
  49. // 'Kota Serang',
  50. // 'Kota Tangerang',
  51. // 'Kota Tangerang Selatan'
  52. // // 8
  53. // ];
  54. // exports.seedBantenCities = async () => {
  55. // const province = await prisma.province.findFirst({
  56. // where: { name: 'Banten' },
  57. // });
  58. // if (!province) {
  59. // console.error('❌ Province Banten not found. Seed it first.');
  60. // return;
  61. // }
  62. // for (const name of cityNames) {
  63. // await prisma.city.upsert({
  64. // where: {
  65. // name_province_id: {
  66. // name,
  67. // province_id: province.id,
  68. // },
  69. // },
  70. // update: {
  71. // updatedAt: timeLocal.now().toDate()
  72. // },
  73. // create: {
  74. // name,
  75. // province_id: province.id,
  76. // createdAt: timeLocal.now().toDate()
  77. // },
  78. // });
  79. // }
  80. // console.log('✅ Banten City seeded!.');
  81. // };