Skip to content

Commit

Permalink
feat: seed category using the existing models
Browse files Browse the repository at this point in the history
  • Loading branch information
zainfathoni committed Sep 20, 2022
1 parent ec12c2b commit 6d49e11
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
27 changes: 27 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -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()
})

0 comments on commit 6d49e11

Please sign in to comment.