feat(github): index connections by installation + status mutation

This commit is contained in:
Gabriel Brown
2026-07-11 14:07:57 -04:00
parent 18cb424b99
commit f7c3aa6482
3 changed files with 86 additions and 1 deletions
+26
View File
@@ -138,6 +138,32 @@ export const upsertConnectionForUser = internalMutation({
},
});
export const setConnectionStatusByInstallation = internalMutation({
args: {
installationId: v.string(),
status: v.union(
v.literal('active'),
v.literal('needs_reauth'),
v.literal('revoked'),
),
},
handler: async (ctx, { installationId, status }) => {
const connections = await ctx.db
.query('gitConnections')
.withIndex('by_installation', (q) =>
q.eq('installationId', installationId),
)
.collect();
const now = Date.now();
for (const connection of connections) {
await ctx.db.patch(connection._id, { status, updatedAt: now });
}
return { updated: connections.length };
},
});
export const createForkSpoonRecord = internalMutation({
args: {
ownerId: v.id('users'),
+2 -1
View File
@@ -53,7 +53,8 @@ const applicationTables = {
})
.index('by_user', ['userId'])
.index('by_user_provider', ['userId', 'provider'])
.index('by_status', ['status']),
.index('by_status', ['status'])
.index('by_installation', ['installationId']),
spoons: defineTable({
ownerId: v.id('users'),
name: v.string(),