Skip to content

Commit 92067df

Browse files
committed
Add a script to copy eval run results to Turso
1 parent 5fa555e commit 92067df

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

evals/packages/db/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"db:check": "pnpm drizzle-kit check",
1616
"db:up": "pnpm drizzle-kit up",
1717
"db:studio": "pnpm drizzle-kit studio",
18-
"db:enable-wal": "dotenvx run -f ../../.env -- tsx scripts/enable-wal.mts"
18+
"db:enable-wal": "dotenvx run -f ../../.env -- tsx scripts/enable-wal.mts",
19+
"db:copy-run": "dotenvx run -f ../../.env -- tsx scripts/copy-run.mts"
1920
},
2021
"dependencies": {
2122
"@evals/types": "workspace:^",
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { drizzle } from "drizzle-orm/libsql"
2+
import { eq } from "drizzle-orm"
3+
4+
import { db as sourceDb } from "../src/db.js"
5+
import { schema } from "../src/schema.js"
6+
7+
const copyRun = async (runId: number) => {
8+
const destDb = drizzle({
9+
schema,
10+
connection: { url: process.env.TURSO_CONNECTION_URL!, authToken: process.env.TURSO_AUTH_TOKEN! },
11+
})
12+
13+
const run = await sourceDb.query.runs.findFirst({
14+
where: eq(schema.runs.id, runId),
15+
with: { taskMetrics: true },
16+
})
17+
18+
if (!run) {
19+
throw new Error(`Run with ID ${runId} not found in source database`)
20+
}
21+
22+
if (!run.taskMetrics) {
23+
throw new Error("Run is not completed")
24+
}
25+
26+
console.log(`Copying run ${run.id}`)
27+
28+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
29+
const { id: _, ...runTaskMetricsValues } = run.taskMetrics
30+
const [newRunTaskMetrics] = await destDb.insert(schema.taskMetrics).values(runTaskMetricsValues).returning()
31+
32+
if (!newRunTaskMetrics) {
33+
throw new Error("Failed to insert run taskMetrics")
34+
}
35+
36+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
37+
const { id: __, ...runValues } = run
38+
39+
const [newRun] = await destDb
40+
.insert(schema.runs)
41+
.values({ ...runValues, taskMetricsId: newRunTaskMetrics.id })
42+
.returning()
43+
44+
if (!newRun) {
45+
throw new Error("Failed to insert run")
46+
}
47+
48+
const tasks = await sourceDb.query.tasks.findMany({
49+
where: eq(schema.tasks.runId, run.id),
50+
with: { taskMetrics: true },
51+
})
52+
53+
console.log(`Copying ${tasks.length} tasks`)
54+
55+
for (const task of tasks) {
56+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
57+
const { id: _, ...newTaskMetricsValues } = task.taskMetrics!
58+
const [newTaskMetrics] = await destDb.insert(schema.taskMetrics).values(newTaskMetricsValues).returning()
59+
60+
if (!newTaskMetrics) {
61+
throw new Error(`Failed to insert taskMetrics for task ${task.id}`)
62+
}
63+
64+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
65+
const { id: __, ...newTaskValues } = task
66+
67+
const [newTask] = await destDb
68+
.insert(schema.tasks)
69+
.values({ ...newTaskValues, runId: newRun.id, taskMetricsId: newTaskMetrics.id })
70+
.returning()
71+
72+
if (!newTask) {
73+
throw new Error(`Failed to insert task ${task.id}`)
74+
}
75+
}
76+
77+
console.log(`Successfully copied run ${runId} with ${tasks.length} tasks`)
78+
}
79+
80+
const main = async () => {
81+
const runId = parseInt(process.argv[2], 10)
82+
83+
if (isNaN(runId)) {
84+
console.error("Run ID must be a number")
85+
process.exit(1)
86+
}
87+
88+
try {
89+
await copyRun(runId)
90+
process.exit(0)
91+
} catch (error) {
92+
console.error(error)
93+
process.exit(1)
94+
}
95+
}
96+
97+
main()

evals/turbo.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"OPENROUTER_MODEL_ID",
1010
"PROMPT_PATH",
1111
"WORKSPACE_PATH",
12-
"BENCHMARKS_DB_PATH"
12+
"BENCHMARKS_DB_PATH",
13+
"TURSO_CONNECTION_URL",
14+
"TURSO_AUTH_TOKEN"
1315
],
1416
"tasks": {
1517
"lint": {},

0 commit comments

Comments
 (0)