diff --git a/package.json b/package.json index 034b944..958228d 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,9 @@ "author": "", "private": true, "license": "UNLICENSED", + "prisma": { + "seed": "ts-node ./prisma/seed.ts" + }, "scripts": { "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", diff --git a/prisma/seed.ts b/prisma/seed.ts new file mode 100644 index 0000000..5ce421e --- /dev/null +++ b/prisma/seed.ts @@ -0,0 +1,25 @@ +import { PrismaClient } from '@prisma/client'; + +const prisma = new PrismaClient(); +async function main() { + await this.prisma.role.create({ + name: 'user', + }); + await this.prisma.role.create({ + name: 'admin', + }); + + await this.prisma.promoCode.create({ + name: 'PROMO1000', + }); +} + +main() + .then(async () => { + await prisma.$disconnect(); + }) + .catch(async (e) => { + console.error(e); + await prisma.$disconnect(); + process.exit(1); + });