Closed lullaaaby13 closed 3 months ago
@lullaaaby13
동성님~~ PR은종료됐지만 도시데이터도 추가할거라서 요러케 분리를 했습니당!
// prisma/functions/add-country.ts
const addCountry = async (prisma) => {
const countries = require('../data/Countries.json');
await Promise.all(
countries.map((it) => {
return prisma.country.create({
data: {
name: it.name,
code: it.id,
},
});
}),
);
};
export default addCountry;
// prisma/seed.ts
import { PrismaClient } from '@prisma/client';
import addCity from './functions/add-city.seed';
import addCountry from './functions/add-country.seed';
const prisma = new PrismaClient();
async function main() {
await addCountry(prisma); // 국가 데이터
await addCity(prisma); // 도시데이터
// 추가적인 데이터 삽입 작업을 여기에 작성할 수 있습니다.
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
함수를 분리시켜서 리팩토링도 할수있습니당!
오 좋은 아이디어 입니다!
⛳️ 기능 구현 배경
🧐 기능 구현 내용(Optional)
📭 이슈 번호
12
🖐️ 의견 구하기
🙏 P.S