-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathseed.ts
More file actions
61 lines (53 loc) · 2.05 KB
/
seed.ts
File metadata and controls
61 lines (53 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { PrismaClient, TaskStatus, TaskPriority } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
// Create users
const users = await Promise.all([
prisma.user.create({ data: { email: 'john@example.com', name: 'John Doe' } }),
prisma.user.create({ data: { email: 'jane@example.com', name: 'Jane Smith' } }),
prisma.user.create({ data: { email: 'bob@example.com', name: 'Bob Johnson' } }),
]);
// Create projects
const projects = await Promise.all([
prisma.project.create({ data: { name: 'Backend API' } }),
prisma.project.create({ data: { name: 'Mobile App' } }),
prisma.project.create({ data: { name: 'Data Migration' } }),
]);
// Create tags
const tags = await Promise.all([
prisma.tag.create({ data: { name: 'bug' } }),
prisma.tag.create({ data: { name: 'feature' } }),
prisma.tag.create({ data: { name: 'enhancement' } }),
prisma.tag.create({ data: { name: 'documentation' } }),
]);
// Create tasks
const statuses = Object.values(TaskStatus);
const priorities = Object.values(TaskPriority);
for (let i = 0; i < 100; i++) {
await prisma.task.create({
data: {
title: `Task ${i + 1}`,
description: `Description for task ${i + 1}`,
status: statuses[Math.floor(Math.random() * statuses.length)],
priority: priorities[Math.floor(Math.random() * priorities.length)],
projectId: projects[Math.floor(Math.random() * projects.length)].id,
assigneeId: Math.random() > 0.3 ? users[Math.floor(Math.random() * users.length)].id : null,
dueDate: Math.random() > 0.5 ? new Date(Date.now() + Math.random() * 30 * 24 * 60 * 60 * 1000) : null,
tags: {
connect: Array(Math.floor(Math.random() * 3))
.fill(null)
.map(() => ({ id: tags[Math.floor(Math.random() * tags.length)].id }))
}
}
});
}
console.log('Seed data created successfully');
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});