chore(db): detectar usuario sin project-ref del pooler en el check de CI#1
Conversation
The CI "Verify Postgres connection" step rejected a valid password with 28P01 because the pooler URI used user `postgres` instead of `postgres.<project-ref>`. Supavisor requires the ref, and the error masquerades as a wrong password. - verify-db-connection.cjs: structural preflight that fails fast with a clear `pooler_user_missing_ref` message, logs a password-free summary of user/host/port, and adds a targeted 28P01 hint. - docs/DATABASE.md: document the 28P01 gotcha and the fix. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Code Review
This pull request documents and adds preflight validation for the Supabase pooler authentication error (28P01), which typically occurs when the database URL is missing the project-ref in the username. The verify-db-connection.cjs script is updated to inspect the connection URL and provide detailed hints on failure. The review feedback suggests two improvements to make the script more robust: handling potential URI malformation errors during username decoding, and wrapping the synchronous database client initialization in a try-catch block to prevent unhandled script crashes.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| function inspectUrl(raw) { | ||
| try { | ||
| const u = new URL(raw); | ||
| const user = decodeURIComponent(u.username); |
There was a problem hiding this comment.
Si el nombre de usuario contiene un carácter % que no forma parte de una secuencia de escape válida, decodeURIComponent lanzará un error URIError: URI malformed. Al estar dentro del bloque try/catch general de inspectUrl, esto provocará que la función devuelva null y se omita por completo la validación previa (preflight check).
Podemos hacer el código más robusto intentando decodificar el usuario y, si falla, usar el valor original sin decodificar para continuar con la validación.
let user = u.username;
try {
user = decodeURIComponent(u.username);
} catch {
// Ignorar error de decodificación y usar el valor original
}
| } | ||
| } | ||
|
|
||
| const sql = postgres(url, { max: 1, ssl: "require", connect_timeout: 20 }); |
There was a problem hiding this comment.
La inicialización de postgres(url, ...) puede lanzar un error de forma síncrona si el formato de la URL es inválido o si hay opciones incompatibles. Dado que esta llamada se encuentra fuera del bloque try/catch de la función autoejecutable asíncrona (IIFE), cualquier error síncrono provocará que el script falle con un stack trace sin capturar, en lugar de mostrar el JSON estructurado esperado por el CI.
Para evitar esto, podemos envolver la inicialización en un bloque try/catch síncrono.
let sql;
try {
sql = postgres(url, { max: 1, ssl: "require", connect_timeout: 20 });
} catch (e) {
console.error(
JSON.stringify({
connectionTest: "failed",
message: e instanceof Error ? e.message : String(e),
}),
);
process.exit(1);
}
CI (ci.yml Lint step) had been failing on main since verify-db-connection.cjs was added: eslint-config-next/typescript applies @typescript-eslint/no-require-imports to .cjs files, where require() is the correct idiom. Disable that rule for **/*.cjs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Qué
El paso Verify Postgres connection del workflow Drizzle DB push rechazaba una contraseña válida con
28P01 password authentication failed for user "postgres"porque la URI del pooler usaba el usuariopostgresen vez depostgres.<project-ref>. Supavisor exige el ref, y el error se disfraza de contraseña incorrecta.Cambios
scripts/verify-db-connection.cjs:*.pooler.supabase.com) y el usuario espostgressin ref, falla rápido conerror: "pooler_user_missing_ref"y un mensaje accionable, sin intentar conectar.user/host/port) para depurar desde el log de CI.28P01según sea pooler o no.docs/DATABASE.md: nueva sección documentando el gotcha del28P01y el fix.Por qué no es urgente
El secreto
DATABASE_URL_DIRECTya está corregido y el workflow corre en verde. Esto es preventivo: si vuelve a pasar, el log lo dirá directo en vez de mandar a perseguir la contraseña.Notas
.envlocal (eso es fuera de git).node --checkOK + test del preflight (caso pooler+user-sin-ref → exit 1 con el mensaje correcto).🤖 Generated with Claude Code