diff --git a/package.json b/package.json index 94be3f3..1f8555d 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,9 @@ "format": "biome format --write .", "postinstall": "prisma generate" }, + "prisma": { + "seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts" + }, "dependencies": { "@prisma/client": "^5.11.0", "@radix-ui/react-dialog": "^1.1.1", diff --git a/prisma/schema.prisma b/prisma/schema.prisma index cd6cce2..4ee152e 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -4,7 +4,7 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") + url = "postgres://test:test@localhost:5432/test" } diff --git a/prisma/seed.ts b/prisma/seed.ts new file mode 100644 index 0000000..5198fdc --- /dev/null +++ b/prisma/seed.ts @@ -0,0 +1,19 @@ +import { ElectionStatus, PrismaClient } from "@prisma/client"; +const prisma = new PrismaClient(); +const candidates: string[] = ["Candidate_1, Candidate_2, Candidate_3"]; + +async function main() { + await prisma.election.create({ + data: { + id: "824a-a25251e23013", + name: "Election 4", + status: ElectionStatus.FINISHED, + candidates: { + create: candidates.map((name) => ({ name })), + }, + }, + }); +} +main().then(async () => { + await prisma.$disconnect(); +});