-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclear-problem.js
More file actions
51 lines (43 loc) · 1.65 KB
/
clear-problem.js
File metadata and controls
51 lines (43 loc) · 1.65 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
require("dotenv").config();
const { PrismaClient } = require("@prisma/client");
const { PrismaPg } = require("@prisma/adapter-pg");
const pg = require("pg");
const pool = new pg.Pool({
connectionString: process.env.DATABASE_URL,
ssl: false,
});
const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({ adapter });
async function clearProblems() {
try {
console.log("🗑️ Clearing all problems and related data from database...");
// First delete all submissions (which reference problems)
const deletedSubmissions = await prisma.submission.deleteMany({});
console.log(`✅ Deleted ${deletedSubmissions.count} submissions`);
// Delete assignment_problems (which reference problems)
const deletedAssignmentProblems = await prisma.assignmentProblem.deleteMany(
{},
);
console.log(
`✅ Deleted ${deletedAssignmentProblems.count} assignment problems`,
);
// Then delete all problems
const deletedProblems = await prisma.problem.deleteMany({});
console.log(`✅ Deleted ${deletedProblems.count} problems`);
// Verify
const problemCount = await prisma.problem.count();
const submissionCount = await prisma.submission.count();
const assignmentProblemCount = await prisma.assignmentProblem.count();
console.log(`\n📊 Final counts:`);
console.log(` Problems: ${problemCount}`);
console.log(` Submissions: ${submissionCount}`);
console.log(` Assignment Problems: ${assignmentProblemCount}`);
} catch (error) {
console.error("❌ Error clearing problems:", error);
throw error;
} finally {
await prisma.$disconnect();
pool.end();
}
}
clearProblems();