Skip to content

Commit 1409d68

Browse files
committed
fea: integrated seeding functionality
1 parent 0653ae5 commit 1409d68

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"format": "biome format --write .",
1313
"postinstall": "prisma generate"
1414
},
15+
"prisma": {
16+
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
17+
},
1518
"dependencies": {
1619
"@prisma/client": "^5.11.0",
1720
"@radix-ui/react-dialog": "^1.1.1",

prisma/seed.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ElectionStatus, PrismaClient } from "@prisma/client";
2+
const prisma = new PrismaClient();
3+
const candidates: string[] = ["Candidate_1, Candidate_2, Candidate_3"];
4+
5+
async function main() {
6+
await prisma.election.create({
7+
data: {
8+
id: "824a-a25251e23013",
9+
name: "Election 4",
10+
status: ElectionStatus.FINISHED,
11+
candidates: {
12+
create: candidates.map((name) => ({ name })),
13+
},
14+
},
15+
});
16+
}
17+
main().then(async () => {
18+
await prisma.$disconnect();
19+
});

0 commit comments

Comments
 (0)