26 lines
820 B
TypeScript
26 lines
820 B
TypeScript
import { v } from 'convex/values';
|
|
|
|
import { internalMutation } from './_generated/server.js';
|
|
|
|
// One-shot backfill: preserve existing automatic fast-forward behavior for
|
|
// GitHub spoons now that refreshes honor autoSyncEnabled. Idempotent.
|
|
export const backfillAutoSyncDefaults = internalMutation({
|
|
args: {},
|
|
returns: v.object({ updated: v.number() }),
|
|
handler: async (ctx) => {
|
|
const settings = await ctx.db.query('spoonSettings').collect();
|
|
let updated = 0;
|
|
for (const row of settings) {
|
|
if (row.autoSyncEnabled) continue;
|
|
const spoon = await ctx.db.get(row.spoonId);
|
|
if (spoon?.provider !== 'github') continue;
|
|
await ctx.db.patch(row._id, {
|
|
autoSyncEnabled: true,
|
|
updatedAt: Date.now(),
|
|
});
|
|
updated += 1;
|
|
}
|
|
return { updated };
|
|
},
|
|
});
|