feat(backend): migration to retire openai_direct runtime

This commit is contained in:
Gabriel Brown
2026-07-11 11:05:12 -04:00
parent 0716a224ef
commit 6ec2e51312
2 changed files with 146 additions and 0 deletions
+32
View File
@@ -23,3 +23,35 @@ export const backfillAutoSyncDefaults = internalMutation({
return { updated };
},
});
// One-shot migration retiring the legacy `openai_direct` runtime literal:
// rewrites any surviving `agentJobs`/`spoonAgentSettings` rows to `opencode`.
// `openai_direct` stays in the schema unions as a legacy-read literal; nothing
// writes it anymore. Run once post-deploy via
// `npx convex run migrations:migrateOpenAiDirectRuntime`. Idempotent.
export const migrateOpenAiDirectRuntime = internalMutation({
args: {},
returns: v.object({ patched: v.number() }),
handler: async (ctx) => {
let patched = 0;
for (const job of await ctx.db.query('agentJobs').collect()) {
if (job.runtime === 'openai_direct') {
await ctx.db.patch(job._id, {
runtime: 'opencode',
updatedAt: Date.now(),
});
patched += 1;
}
}
for (const settings of await ctx.db.query('spoonAgentSettings').collect()) {
if (settings.runtime === 'openai_direct') {
await ctx.db.patch(settings._id, {
runtime: 'opencode',
updatedAt: Date.now(),
});
patched += 1;
}
}
return { patched };
},
});