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

fix: remove duplicate neon pooler #990

Merged
merged 5 commits into from
Mar 7, 2024
Merged

fix: remove duplicate neon pooler #990

merged 5 commits into from
Mar 7, 2024

Conversation

dguyen
Copy link
Collaborator

@dguyen dguyen commented Mar 6, 2024

Description

Fixes the issue with Vercel preview deployments failing.

It appears that the old PGHOST environment variable injected by neon was:

ep-snowy-snowflake-a2vc5pa2.eu-central-1.aws.neon.tech

It is now:

ep-snowy-snowflake-a2vc5pa2.eu-central-1-pooler.aws.neon.tech

Notice the -pooler being attached automatically to the PGHOST.

References

The following changes were made to the Neon Vercel Integration:

To ensure that users accessing a Neon database from a serverless environment have enough connections, the DATABASE_URL and PGHOST environment variables added to a Vercel project by the Neon integration are now set to a pooled Neon connection string by default. Pooled connections support up to 10,000 simultaneous connections. Previously, these variables were set to an unpooled connection string supporting fewer concurrent connections.

https://neon.tech/docs/changelog

https://neon.tech/docs/guides/vercel#manage-vercel-environment-variables

Copy link
Contributor

coderabbitai bot commented Mar 6, 2024

Important

Auto Review Skipped

Auto reviews are limited to the following labels: coderabbit. Please add one of these labels to enable auto reviews.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

vercel bot commented Mar 6, 2024

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

Name Status Preview Comments Updated (UTC)
stg-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 7, 2024 4:59am
stg-marketing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 7, 2024 4:59am
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
prd-app ⬜️ Ignored (Inspect) Mar 7, 2024 4:59am
prd-marketing ⬜️ Ignored (Inspect) Mar 7, 2024 4:59am

@dguyen dguyen marked this pull request as draft March 6, 2024 08:44
@dguyen dguyen marked this pull request as ready for review March 6, 2024 08:47
Copy link
Collaborator

Mythie commented Mar 6, 2024

de nada

PGBOUNCER_HOST="$(echo "$PGHOST" | sed "s/${PROJECT_ID}/${PROJECT_ID}-pooler/")"

export NEXT_PRIVATE_DATABASE_URL="postgres://${PGUSER}:${PGPASSWORD}@${PGBOUNCER_HOST}/${PGDATABASE}?pgbouncer=true"
export NEXT_PRIVATE_DATABASE_URL="postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}/${PGDATABASE}?pgbouncer=true"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we need to account for the direct database url so prisma migrations can run 🥲

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we have a repeat of the logic in packages/prisma/helper.ts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we need to account for the direct database url so prisma migrations can run 🥲

Apparently if we upgrade prisma to 5.10 it lets us migrate using a connection pool?

https://neon.tech/docs/guides/prisma#connection-pooling-with-prisma-migrate

Also we have a repeat of the logic in packages/prisma/helper.ts

The logic in the helper checks whether pooler is already attached, want me to try clean it up anyway?

  // Support for neon.tech (Neon Database)
  if (url.hostname.endsWith('neon.tech')) {
    const [projectId, ...rest] = url.hostname.split('.');

    if (!projectId.endsWith('-pooler')) {
      url.hostname = `${projectId}-pooler.${rest.join('.')}`;
    }

    url.searchParams.set('pgbouncer', 'true');

    process.env.NEXT_PRIVATE_DATABASE_URL = url.toString().replace('https://', 'postgres://');
  }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what was the reason we can't use the direct database URL for neon for migrations?

@dguyen
Copy link
Collaborator Author

dguyen commented Mar 7, 2024

@Mythie could you please have a look when possible

  • Updated the Neon/Vercel integration to pass in DATABASE_URL_UNPOOLED
  • Updated scripts to use this when required
  • Catch all seed errors since they should not stop a migration/build from running (maybe we should actually fix all the invalid seeds when they run twice?)

Created example PR with a migration, since this variable is only created for new branches:

#992

Not sure if this will conflict with any thing on production since this should only be for previews

Copy link
Collaborator

@Mythie Mythie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but also too big brain for me to fully understand anymore

@dguyen dguyen merged commit f6eddaa into main Mar 7, 2024
13 checks passed
@dguyen dguyen deleted the fix/neon-db branch March 7, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants