-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add a script to copy eval run results to Turso #2452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { drizzle } from "drizzle-orm/libsql" | ||
| import { eq } from "drizzle-orm" | ||
|
|
||
| import { db as sourceDb } from "../src/db.js" | ||
| import { schema } from "../src/schema.js" | ||
|
|
||
| const copyRun = async (runId: number) => { | ||
| const destDb = drizzle({ | ||
| schema, | ||
| connection: { url: process.env.TURSO_CONNECTION_URL!, authToken: process.env.TURSO_AUTH_TOKEN! }, | ||
| }) | ||
|
|
||
| const run = await sourceDb.query.runs.findFirst({ | ||
| where: eq(schema.runs.id, runId), | ||
| with: { taskMetrics: true }, | ||
| }) | ||
|
|
||
| if (!run) { | ||
| throw new Error(`Run with ID ${runId} not found in source database`) | ||
| } | ||
|
|
||
| if (!run.taskMetrics) { | ||
| throw new Error("Run is not completed") | ||
| } | ||
|
|
||
| console.log(`Copying run ${run.id}`) | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| const { id: _, ...runTaskMetricsValues } = run.taskMetrics | ||
| const [newRunTaskMetrics] = await destDb.insert(schema.taskMetrics).values(runTaskMetricsValues).returning() | ||
|
|
||
| if (!newRunTaskMetrics) { | ||
| throw new Error("Failed to insert run taskMetrics") | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| const { id: __, ...runValues } = run | ||
|
|
||
| const [newRun] = await destDb | ||
| .insert(schema.runs) | ||
| .values({ ...runValues, taskMetricsId: newRunTaskMetrics.id }) | ||
| .returning() | ||
|
|
||
| if (!newRun) { | ||
| throw new Error("Failed to insert run") | ||
| } | ||
|
|
||
| const tasks = await sourceDb.query.tasks.findMany({ | ||
| where: eq(schema.tasks.runId, run.id), | ||
| with: { taskMetrics: true }, | ||
| }) | ||
|
|
||
| console.log(`Copying ${tasks.length} tasks`) | ||
|
|
||
| for (const task of tasks) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loop inserting each task and its taskMetrics might benefit from a transaction to ensure atomicity and data consistency. Consider wrapping these DB operations in a transaction. |
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| const { id: _, ...newTaskMetricsValues } = task.taskMetrics! | ||
| const [newTaskMetrics] = await destDb.insert(schema.taskMetrics).values(newTaskMetricsValues).returning() | ||
|
|
||
| if (!newTaskMetrics) { | ||
| throw new Error(`Failed to insert taskMetrics for task ${task.id}`) | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| const { id: __, ...newTaskValues } = task | ||
|
|
||
| const [newTask] = await destDb | ||
| .insert(schema.tasks) | ||
| .values({ ...newTaskValues, runId: newRun.id, taskMetricsId: newTaskMetrics.id }) | ||
| .returning() | ||
|
|
||
| if (!newTask) { | ||
| throw new Error(`Failed to insert task ${task.id}`) | ||
| } | ||
| } | ||
|
|
||
| console.log(`Successfully copied run ${runId} with ${tasks.length} tasks`) | ||
| } | ||
|
|
||
| const main = async () => { | ||
| const runId = parseInt(process.argv[2], 10) | ||
|
|
||
| if (isNaN(runId)) { | ||
| console.error("Run ID must be a number") | ||
| process.exit(1) | ||
| } | ||
|
|
||
| try { | ||
| await copyRun(runId) | ||
| process.exit(0) | ||
| } catch (error) { | ||
| console.error(error) | ||
| process.exit(1) | ||
| } | ||
| } | ||
|
|
||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider checking that
TURSO_CONNECTION_URLandTURSO_AUTH_TOKENare defined instead of using non-null assertions. This improves error clarity if the env variables are missing.