KepulauanBangkaBelitungCitySeeder.ts 2.5 KB

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