mirror of
https://github.com/documenso/documenso.git
synced 2025-11-09 20:12:31 +10:00
fix: remove duplicate neon pooler (#990)
## 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](https://vercel.com/integrations/neon): > >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
This commit is contained in:
@ -15,6 +15,10 @@ export const getDatabaseUrl = () => {
|
||||
process.env.NEXT_PRIVATE_DIRECT_DATABASE_URL = process.env.DATABASE_URL;
|
||||
}
|
||||
|
||||
if (process.env.DATABASE_URL_UNPOOLED) {
|
||||
process.env.NEXT_PRIVATE_DIRECT_DATABASE_URL = process.env.DATABASE_URL_UNPOOLED;
|
||||
}
|
||||
|
||||
if (process.env.POSTGRES_PRISMA_URL) {
|
||||
process.env.NEXT_PRIVATE_DATABASE_URL = process.env.POSTGRES_PRISMA_URL;
|
||||
}
|
||||
@ -40,18 +44,5 @@ export const getDatabaseUrl = () => {
|
||||
process.env.NEXT_PRIVATE_DATABASE_URL = url.toString().replace('https://', 'postgres://');
|
||||
}
|
||||
|
||||
// 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://');
|
||||
}
|
||||
|
||||
return process.env.NEXT_PRIVATE_DATABASE_URL;
|
||||
};
|
||||
|
||||
@ -13,7 +13,13 @@ const seedDatabase = async () => {
|
||||
|
||||
if ('seedDatabase' in mod && typeof mod.seedDatabase === 'function') {
|
||||
console.log(`[SEEDING]: ${file}`);
|
||||
await mod.seedDatabase();
|
||||
|
||||
try {
|
||||
await mod.seedDatabase();
|
||||
} catch (e) {
|
||||
console.log(`[SEEDING]: Seed failed for ${file}`);
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ set -eo pipefail
|
||||
# Get the directory of this script, regardless of where it is called from.
|
||||
SCRIPT_DIR="$(readlink -f "$(dirname "$0")")"
|
||||
|
||||
|
||||
function log() {
|
||||
echo "[VercelBuild]: $1"
|
||||
}
|
||||
@ -69,19 +68,17 @@ function remap_database_integration() {
|
||||
export NEXT_PRIVATE_DIRECT_DATABASE_URL="$DATABASE_URL"
|
||||
fi
|
||||
|
||||
if [[ ! -z "$DATABASE_URL_UNPOOLED" ]]; then
|
||||
log "Remapping for Neon integration"
|
||||
|
||||
export NEXT_PRIVATE_DATABASE_URL="$DATABASE_URL&pgbouncer=true"
|
||||
export NEXT_PRIVATE_DIRECT_DATABASE_URL="$DATABASE_URL_UNPOOLED"
|
||||
fi
|
||||
|
||||
if [[ ! -z "$POSTGRES_URL_NON_POOLING" ]]; then
|
||||
export NEXT_PRIVATE_DATABASE_URL="$POSTGRES_URL?pgbouncer=true"
|
||||
export NEXT_PRIVATE_DIRECT_DATABASE_URL="$POSTGRES_URL_NON_POOLING"
|
||||
fi
|
||||
|
||||
if [[ "$NEXT_PRIVATE_DATABASE_URL" == *"neon.tech"* ]]; then
|
||||
log "Remapping for Neon integration"
|
||||
|
||||
PROJECT_ID="$(echo "$PGHOST" | cut -d'.' -f1)"
|
||||
PGBOUNCER_HOST="$(echo "$PGHOST" | sed "s/${PROJECT_ID}/${PROJECT_ID}-pooler/")"
|
||||
|
||||
export NEXT_PRIVATE_DATABASE_URL="postgres://${PGUSER}:${PGPASSWORD}@${PGBOUNCER_HOST}/${PGDATABASE}?pgbouncer=true"
|
||||
fi
|
||||
}
|
||||
|
||||
# Navigate to the root of the project.
|
||||
|
||||
@ -90,6 +90,7 @@
|
||||
"FONT_CAVEAT_URI",
|
||||
"POSTGRES_URL",
|
||||
"DATABASE_URL",
|
||||
"DATABASE_URL_UNPOOLED",
|
||||
"POSTGRES_PRISMA_URL",
|
||||
"POSTGRES_URL_NON_POOLING",
|
||||
"E2E_TEST_AUTHENTICATE_USERNAME",
|
||||
|
||||
Reference in New Issue
Block a user