From 2fdc16e00366e02ddd3275f285dd3fdba08564bf Mon Sep 17 00:00:00 2001 From: Mathis Date: Tue, 12 Nov 2024 13:30:21 +0100 Subject: [PATCH] Add initial seeding script for roles and promo codes This commit introduces a new seed script located at prisma/seed.ts. The script seeds the database with default roles ('user' and 'admin') and a sample promo code ('PROMO1000' with a value of 1000). This setup helps initialize essential data for application functionality. --- prisma/seed.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 prisma/seed.ts diff --git a/prisma/seed.ts b/prisma/seed.ts new file mode 100644 index 0000000..bdcfdf6 --- /dev/null +++ b/prisma/seed.ts @@ -0,0 +1,34 @@ +import { PrismaClient } from '@prisma/client'; + +const prisma = new PrismaClient(); + +async function main() { + await prisma.role.create({ + data: { + name: 'user', + }, + }); + await prisma.role.create({ + data: { + name: 'admin', + }, + }); + + await prisma.promoCode.create({ + data: { + name: 'PROMO1000', + value: 1000, + }, + }); +} + +main() + .then(async () => { + await prisma.$disconnect(); + }) + .catch(async (e) => { + console.error(e); + await prisma.$disconnect(); + process.exit(1); + }); +