backfill improvements

This commit is contained in:
Vikhyath Mondreti
2026-02-13 16:26:13 -08:00
parent 93826cbd1a
commit d70a5d4271
4 changed files with 27 additions and 2 deletions

View File

@@ -184,7 +184,7 @@ export async function GET(request: NextRequest) {
}
if (lookupCredentialId) {
const [row] = await db
let [row] = await db
.select({
id: credential.id,
displayName: credential.displayName,
@@ -195,6 +195,24 @@ export async function GET(request: NextRequest) {
.where(and(eq(credential.id, lookupCredentialId), eq(credential.workspaceId, workspaceId)))
.limit(1)
if (!row) {
;[row] = await db
.select({
id: credential.id,
displayName: credential.displayName,
type: credential.type,
providerId: credential.providerId,
})
.from(credential)
.where(
and(
eq(credential.accountId, lookupCredentialId),
eq(credential.workspaceId, workspaceId)
)
)
.limit(1)
}
return NextResponse.json({ credential: row ?? null })
}

View File

@@ -133,6 +133,9 @@ export function CredentialSelector({
if (!response.ok || cancelled) return
const data = await response.json()
if (!cancelled && data.credential?.displayName) {
if (data.credential.id !== selectedId) {
setStoreValue(data.credential.id)
}
setInaccessibleCredentialName(data.credential.displayName)
}
} catch {

View File

@@ -109,6 +109,9 @@ export function ToolCredentialSelector({
if (!response.ok || cancelled) return
const data = await response.json()
if (!cancelled && data.credential?.displayName) {
if (data.credential.id !== selectedId) {
onChange(data.credential.id)
}
setInaccessibleCredentialName(data.credential.displayName)
}
} catch {

View File

@@ -145,7 +145,7 @@ oauth_creds AS (
'cred_' || md5(wua.workspace_id || ':' || a.id) AS id,
wua.workspace_id,
'oauth'::"credential_type",
'Default ' || COALESCE(pn.sname, a.provider_id) || ' Credential',
COALESCE(u.name, 'User') || '''s ' || COALESCE(pn.sname, a.provider_id),
a.provider_id,
a.id,
a.user_id,
@@ -153,6 +153,7 @@ oauth_creds AS (
now()
FROM "account" a
INNER JOIN workspace_user_access wua ON wua.user_id = a.user_id
INNER JOIN "user" u ON u.id = a.user_id
LEFT JOIN provider_names pn ON pn.pid = a.provider_id
WHERE a.provider_id != 'credential'
ON CONFLICT DO NOTHING