mig: scope user oauth tokens to toolset#1478
Conversation
|
There was a problem hiding this comment.
Devin Review found 1 potential issue.
🔴 1 issue in files not directly in the diff
🔴 UpsertUserOAuthToken ON CONFLICT clause references non-existent unique index (server/internal/oauth/repo/queries.sql:138)
The UpsertUserOAuthToken query uses ON CONFLICT (user_id, organization_id, oauth_server_issuer) but the migration changes the unique index to (user_id, organization_id, toolset_id). After the migration runs, the ON CONFLICT clause will not match any unique constraint.
Click to expand
Impact
When a user completes OAuth authentication and the system tries to store/update their token via UpsertUserOAuthToken at server/internal/oauth/external_oauth.go:479, PostgreSQL will either:
- Raise an error because the ON CONFLICT target doesn't match any unique constraint
- Insert duplicate rows instead of updating existing ones
Actual vs Expected
- Actual: The query's ON CONFLICT references
(user_id, organization_id, oauth_server_issuer)which no longer has a unique index - Expected: The ON CONFLICT should reference
(user_id, organization_id, toolset_id)to match the new unique index
Code Reference
The migration at server/migrations/20260203225638_index-user-tokens-by-toolset-id.sql:6 creates:
CREATE UNIQUE INDEX ... ON "user_oauth_tokens" ("user_id", "organization_id", "toolset_id")But the query at server/internal/oauth/repo/queries.sql:138 still uses:
ON CONFLICT (user_id, organization_id, oauth_server_issuer) WHERE deleted IS FALSE DO UPDATE SETRecommendation: Update the ON CONFLICT clause to use (user_id, organization_id, toolset_id) to match the new unique index. Also update the DO UPDATE SET clause to include toolset_id = EXCLUDED.toolset_id if needed, and consider whether client_registration_id and project_id should also be updated.
View issue and 4 additional flags in Devin Review.
|
|
||||||||||||||||
|
|
||||||||||||||||
🚀 Preview Environment (PR #1478)Preview URL: https://pr-1478.dev.getgram.ai
Gram Preview Bot |
This migration indexes user OAuth tokens by
toolset_idinstead of Issuer.