BaliCitySeeder.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import prisma from '../../../src/prisma/PrismaClient';
  2. import { now } from '../../../src/utils/TimeLocal';
  3. const cityNames: string[] = [
  4. 'Kabupaten Badung',
  5. 'Kabupaten Bangli',
  6. 'Kabupaten Buleleng',
  7. 'Kabupaten Gianyar',
  8. 'Kabupaten Jembrana',
  9. 'Kabupaten Karangasem',
  10. 'Kabupaten Klungkung',
  11. 'Kabupaten Tabanan',
  12. 'Kota Denpasar'
  13. ];
  14. export async function seedBaliCities(): Promise<void> {
  15. const province = await prisma.province.findFirst({
  16. where: { name: 'Bali' },
  17. });
  18. if (!province) {
  19. console.error('❌ Province Bali 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('✅ Bali City seeded!');
  41. }
  42. // const prisma = require('../../../src/prisma/PrismaClient.js');
  43. // const timeLocal = require('../../../src/utils/TimeLocal.js')
  44. // const cityNames = [
  45. // 'Kabupaten Badung',
  46. // 'Kabupaten Bangli',
  47. // 'Kabupaten Buleleng',
  48. // 'Kabupaten Gianyar',
  49. // 'Kabupaten Jembrana',
  50. // 'Kabupaten Karangasem',
  51. // 'Kabupaten Klungkung',
  52. // 'Kabupaten Tabanan',
  53. // 'Kota Denpasar'
  54. // // 9
  55. // ];
  56. // exports.seedBaliCities = async () => {
  57. // const province = await prisma.province.findFirst({
  58. // where: { name: 'Bali' },
  59. // });
  60. // if (!province) {
  61. // console.error('❌ Province Bali 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: {
  73. // updatedAt: timeLocal.now().toDate()
  74. // },
  75. // create: {
  76. // name,
  77. // province_id: province.id,
  78. // createdAt: timeLocal.now().toDate()
  79. // },
  80. // });
  81. // }
  82. // console.log('✅ Bali City seeded!.');
  83. // };