From 6d49e11e4cea01215cc91ef78aa0603d20c71b42 Mon Sep 17 00:00:00 2001 From: Zain Fathoni Date: Tue, 20 Sep 2022 18:01:43 +0800 Subject: [PATCH] feat: seed category using the existing models --- package.json | 3 +++ prisma/seed.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 prisma/seed.ts diff --git a/package.json b/package.json index 20f333b..7180b42 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,9 @@ "name": "remix-template-deno", "private": true, "sideEffects": false, + "prisma": { + "seed": "node --require esbuild-register prisma/seed.ts" + }, "scripts": { "generate:css": "npx tailwindcss -o ./app/tailwind.css", "build": "run-s build:*", diff --git a/prisma/seed.ts b/prisma/seed.ts new file mode 100644 index 0000000..4151a90 --- /dev/null +++ b/prisma/seed.ts @@ -0,0 +1,27 @@ +import { PrismaClient } from '@prisma/client' +import { categories } from '../app/model/categories' + +const prisma = new PrismaClient() + +async function main() { + // create categories + await Promise.all([ + categories.map(async (category) => { + await prisma.category.create({ + data: { + title: category.title, + slug: category.slug, + }, + }) + }), + ]) +} + +main() + .catch((e) => { + console.error(e) + process.exit(1) + }) + .finally(async () => { + await prisma.$disconnect() + })