🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(web): warn about unencoded special characters in DATABASE_URL on migration failure (#13186)
Steffen Schmitzd8bab6b29f85
diff --git a/web/entrypoint.sh b/web/entrypoint.shindex 00bcd37fe9..9061847427 100644--- a/web/entrypoint.sh+++ b/web/entrypoint.sh@@ -1,5 +1,61 @@#!/bin/sh+# Check whether a database URL's credentials contain characters that typically+# need percent-encoding for Prisma (@ : / % # ?). Best-effort heuristic —+# strips the scheme, extracts the authority (user:pass@host) before the first+# slash, and checks for common offenders. Strips %XX sequences first so+# partially-encoded values are caught.+check_unencoded_credentials() {+ _url="$1"+ _no_scheme="${_url#*://}"+ # Extract authority (before first /) so @/# in path or query params+ # don't confuse credential parsing.+ _authority="${_no_scheme%%/*}"+ case "$_authority" in+ *@*)+ _host_part="${_authority##*@}"+ _creds="${_authority%@"$_host_part"}"+ _user="${_creds%%:*}"+ _pass="${_creds#*:}"+ _found=""+ for _val in "$_user" "$_pass"; do+ # Strip valid percent-encoded sequences before checking so+ # partially-encoded values like p%40ss@word are still caught.+ _stripped=$(printf '%s' "$_val" | sed 's/%[0-9A-Fa-f][0-9A-Fa-f]//g')+ case "$_stripped" in+ *@*|*:*|*/*|*%*|*'#'*|*'?'*) _found="true" ;;+ esac+ done+ if [ "$_found" = "true" ]; then+ echo "HINT: Your DATABASE_URL / DIRECT_URL credentials appear to contain special characters (@, :, /, %, #, ?) that are not URL-encoded."+ echo " Prisma requires these to be percent-encoded, otherwise you will see P1013 errors."+ echo " Example: p@ssword → p%40ssword"+ echo " Reference: https://www.prisma.io/docs/orm/reference/connection-urls#special-characters"+ fi+ ;;+ esac+}++# Check whether CLICKHOUSE_PASSWORD contains characters that would break the+# query-string interpolation used in the migration script (& = # ? % + @ space).+# Strips %XX sequences first so partially-encoded values are caught.+check_clickhouse_password() {+ _pass="$1"+ if [ -z "$_pass" ]; then+ return+ fi+ # Strip valid percent-encoded sequences before checking so+ # partially-encoded values are still caught.+ _stripped=$(printf '%s' "$_pass" | sed 's/%[0-9A-Fa-f][0-9A-Fa-f]//g')+ case "$_stripped" in+ *'&'*|*'='*|*'#'*|*'?'*|*'%'*|*'+'*|*'@'*|*' '*)+ echo "HINT: Your CLICKHOUSE_PASSWORD contains special characters (&, =, #, ?, %, +, @, space) that may break the migration URL."+ echo " These characters need to be percent-encoded when passed as query parameters."+ echo " Example: p@ss&word → p%40ss%26word"+ ;;+ esac+}+# Run cleanup script before running migrations# Check if DATABASE_URL is not setif [ -z "$DATABASE_URL" ]; then@@ -41,7 +97,10 @@ status=$?# If migration fails (returns non-zero exit status), exit script with that statusif [ $status -ne 0 ]; then- echo "Applying database migrations failed. This is mostly caused by the database being unavailable."+ echo "Applying database migrations failed. Common causes:"+ echo " 1. The database is unavailable or unreachable."+ echo " 2. DATABASE_URL / DIRECT_URL credentials contain special characters that are not URL-encoded."+ check_unencoded_credentials "$DIRECT_URL"echo "Exiting..."exit $statusfi@@ -57,7 +116,10 @@ fi# If migration fails (returns non-zero exit status), exit script with that statusif [ $status -ne 0 ]; then- echo "Applying clickhouse migrations failed. This is mostly caused by the database being unavailable."+ echo "Applying clickhouse migrations failed. Common causes:"+ echo " 1. The database is unavailable or unreachable."+ echo " 2. CLICKHOUSE_PASSWORD contains special characters that are not URL-encoded."+ check_clickhouse_password "$CLICKHOUSE_PASSWORD"echo "Exiting..."exit $statusfi