Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(adapter-pg): define foreign keys, use single queries #10733

Closed
wants to merge 1 commit into from

Conversation

kevinji
Copy link

@kevinji kevinji commented Apr 26, 2024

☕️ Reasoning

  • Foreign keys are added linking userId to the id in users with cascading delete. The delete user query can now be a single one due to cascading deletes.
  • The id in sessions is deleted and the primary key replaced with sessionToken, which needs to be unique anyways. Turning it into the primary key should also speed up WHERE sessionToken queries.
  • Queries that were previously a SELECT then UPDATE are now a single UPDATE to ensure atomicity. This required creating a rather ugly createParameterizedUpdate function to only join together key = $2 if it exists in the passed-in object. I was unable to figure out the right incantation of TypeScript types to make createParameterizedUpdate type-safe but happy to accept any suggestions to fix this.

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

🎫 Affected issues

📌 Resources

@kevinji kevinji requested a review from ndom91 as a code owner April 26, 2024 08:16
Copy link

vercel bot commented Apr 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 26, 2024 8:23am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Apr 26, 2024 8:23am

@github-actions github-actions bot added adapters Changes related to the core code concerning database adapters pg labels Apr 26, 2024
Many of the multi-queries result in race conditions that can be avoided
if only a single query is used.
@kevinji
Copy link
Author

kevinji commented May 9, 2024

Closing due to lack of attention from reviewers and also that I've switched to using https://github.com/lucia-auth/lucia instead.

@kevinji kevinji closed this May 9, 2024
@kevinji kevinji deleted the patch-2 branch May 9, 2024 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters pg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant