-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed-database.js
More file actions
149 lines (133 loc) · 4.53 KB
/
seed-database.js
File metadata and controls
149 lines (133 loc) · 4.53 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function seedDatabase() {
console.log('🌱 Seeding Supabase database...');
try {
// Create a sample user
const user = await prisma.user.upsert({
where: { email: 'demo@example.com' },
update: {},
create: {
username: 'demo_user',
email: 'demo@example.com',
name: 'Demo User',
},
});
console.log('✅ Created user:', user.username);
// Create a sample contest
const contest = await prisma.contest.upsert({
where: { id: '00000000-0000-0000-0000-000000000001' },
update: {},
create: {
id: '00000000-0000-0000-0000-000000000001',
title: 'Judge0 Programming Contest',
startTime: new Date('2025-01-15T10:00:00Z'),
endTime: new Date('2025-01-15T13:00:00Z'),
disableCopyPaste: false,
preventTabSwitching: false,
requireFullScreen: false,
blockNavigation: false,
webcamMonitoring: false,
},
});
console.log('✅ Created contest:', contest.title);
// Create sample questions
const question1 = await prisma.question.upsert({
where: { id: '00000000-0000-0000-0000-000000000001' },
update: {},
create: {
id: '00000000-0000-0000-0000-000000000001',
contestId: contest.id,
title: 'Two Sum Problem',
description: `Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.`,
inputFormat: 'First line contains n (size of array)\nSecond line contains n space-separated integers\nThird line contains target integer',
outputFormat: 'Two integers representing the indices (0-based) separated by space',
constraints: '2 ≤ n ≤ 1000\n-1000 ≤ nums[i] ≤ 1000\n-2000 ≤ target ≤ 2000',
sampleInput: '4\n2 7 11 15\n9',
sampleOutput: '0 1',
points: 100,
},
});
const question2 = await prisma.question.upsert({
where: { id: '00000000-0000-0000-0000-000000000002' },
update: {},
create: {
id: '00000000-0000-0000-0000-000000000002',
contestId: contest.id,
title: 'Palindrome Check',
description: `Write a program to check if a given string is a palindrome.
A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward.`,
inputFormat: 'A single line containing a string',
outputFormat: 'Print "YES" if palindrome, "NO" otherwise',
constraints: '1 ≤ length of string ≤ 1000\nString contains only lowercase letters',
sampleInput: 'racecar',
sampleOutput: 'YES',
points: 50,
},
});
console.log('✅ Created questions:', [question1.title, question2.title]);
// Create test cases for Two Sum
await prisma.testCase.createMany({
data: [
{
questionId: question1.id,
input: '4\n2 7 11 15\n9',
output: '0 1',
isHidden: false,
},
{
questionId: question1.id,
input: '3\n3 2 4\n6',
output: '1 2',
isHidden: true,
},
{
questionId: question1.id,
input: '2\n3 3\n6',
output: '0 1',
isHidden: true,
},
],
skipDuplicates: true,
});
// Create test cases for Palindrome Check
await prisma.testCase.createMany({
data: [
{
questionId: question2.id,
input: 'racecar',
output: 'YES',
isHidden: false,
},
{
questionId: question2.id,
input: 'hello',
output: 'NO',
isHidden: true,
},
{
questionId: question2.id,
input: 'madam',
output: 'YES',
isHidden: true,
},
],
skipDuplicates: true,
});
console.log('✅ Created test cases');
console.log('🎉 Database seeded successfully!');
console.log('\n📋 Summary:');
console.log(`- Users: 1`);
console.log(`- Contests: 1`);
console.log(`- Questions: 2`);
console.log(`- Test Cases: 6`);
console.log('\n🌐 You can now visit http://localhost:3002/contests to see the contest!');
} catch (error) {
console.error('❌ Error seeding database:', error);
} finally {
await prisma.$disconnect();
}
}
seedDatabase();