Skip to content

chore(db): detectar usuario sin project-ref del pooler en el check de CI#1

Merged
gonzalezulises merged 2 commits into
mainfrom
chore/harden-db-verify
Jun 8, 2026
Merged

chore(db): detectar usuario sin project-ref del pooler en el check de CI#1
gonzalezulises merged 2 commits into
mainfrom
chore/harden-db-verify

Conversation

@gonzalezulises

Copy link
Copy Markdown
Owner

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 usuario postgres en vez de postgres.<project-ref>. Supavisor exige el ref, y el error se disfraza de contraseña incorrecta.

Cambios

  • scripts/verify-db-connection.cjs:
    • Preflight estructural: si el host es el pooler (*.pooler.supabase.com) y el usuario es postgres sin ref, falla rápido con error: "pooler_user_missing_ref" y un mensaje accionable, sin intentar conectar.
    • Loguea un resumen sin contraseña (user / host / port) para depurar desde el log de CI.
    • Pista específica para 28P01 según sea pooler o no.
  • docs/DATABASE.md: nueva sección documentando el gotcha del 28P01 y el fix.

Por qué no es urgente

El secreto DATABASE_URL_DIRECT ya 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

  • No incluye el item del .env local (eso es fuera de git).
  • Verificado: node --check OK + test del preflight (caso pooler+user-sin-ref → exit 1 con el mensaje correcto).

🤖 Generated with Claude Code

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>
@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
opsflow Ready Ready Preview, Comment Jun 8, 2026 12:12pm

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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 });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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>
@gonzalezulises gonzalezulises merged commit 7e35da9 into main Jun 8, 2026
5 checks passed
@gonzalezulises gonzalezulises deleted the chore/harden-db-verify branch June 8, 2026 12:13
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.

2 participants