improvement(migrations): log better errors#4260
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Enhances Reviewed by Cursor Bugbot for commit 96a3b51. Configure here. |
Greptile SummaryThis PR makes two improvements to the migration tooling: it moves the Confidence Score: 5/5Safe to merge; the SQL fix is correct and the only finding is a P2 naming mismatch in the logging helper Both changes are low-risk: the SQL migration fix is a correctness improvement to an existing migration, and the migrate.ts change only affects error logging output. The one identified issue (snake_case vs camelCase field names) means a few diagnostic fields would silently not print, but does not affect migration correctness or CI. packages/db/scripts/migrate.ts — camelCase field names should be verified against the postgres.js driver Important Files Changed
Sequence DiagramsequenceDiagram
participant Runner as migrate.ts
participant Drizzle as drizzle migrate()
participant PG as PostgreSQL
Runner->>Drizzle: migrate(client, { migrationsFolder })
Drizzle->>PG: Apply SQL statements
alt Success
PG-->>Drizzle: OK
Drizzle-->>Runner: resolved
Runner->>Runner: console.log("Migrations applied successfully.")
else Error
PG-->>Drizzle: PostgresError (code, detail, hint, constraint, ...)
Drizzle-->>Runner: throws error
Runner->>Runner: printMigrationError(error)
Note over Runner: Logs message, PG fields,<br/>failing query, cause chain, stack
Runner->>Runner: process.exit(1)
end
Runner->>PG: client.end()
Reviews (1): Last reviewed commit: "improvement(migrations): log better erro..." | Re-trigger Greptile |
| const pgFields = [ | ||
| 'code', | ||
| 'severity', | ||
| 'severity_local', | ||
| 'detail', | ||
| 'hint', | ||
| 'schema', | ||
| 'schema_name', | ||
| 'table', | ||
| 'table_name', | ||
| 'column', | ||
| 'column_name', | ||
| 'constraint', | ||
| 'constraint_name', | ||
| 'data_type', | ||
| 'where', | ||
| 'internal_query', | ||
| 'internal_position', | ||
| 'position', | ||
| 'routine', | ||
| 'file', | ||
| 'line', | ||
| ] as const |
There was a problem hiding this comment.
Some snake_case field names won't match postgres.js error fields
The postgres (porsager/postgres) driver uses camelCase for several extended error fields. The entries internal_query, internal_position, data_type, and severity_local will never match a property on a PostgresError object — the driver actually exposes internalQuery, internalPosition, dataType, and severityLocal. These fields are silent no-ops today, meaning useful diagnostics (especially internalQuery, which shows the PL/pgSQL statement that failed) are silently dropped.
| const pgFields = [ | |
| 'code', | |
| 'severity', | |
| 'severity_local', | |
| 'detail', | |
| 'hint', | |
| 'schema', | |
| 'schema_name', | |
| 'table', | |
| 'table_name', | |
| 'column', | |
| 'column_name', | |
| 'constraint', | |
| 'constraint_name', | |
| 'data_type', | |
| 'where', | |
| 'internal_query', | |
| 'internal_position', | |
| 'position', | |
| 'routine', | |
| 'file', | |
| 'line', | |
| ] as const | |
| const pgFields = [ | |
| 'code', | |
| 'severity', | |
| 'severityLocal', | |
| 'detail', | |
| 'hint', | |
| 'schema', | |
| 'schemaName', | |
| 'table', | |
| 'tableName', | |
| 'column', | |
| 'columnName', | |
| 'constraint', | |
| 'constraintName', | |
| 'dataType', | |
| 'dataTypeName', | |
| 'where', | |
| 'internalQuery', | |
| 'internalPosition', | |
| 'position', | |
| 'routine', | |
| 'file', | |
| 'line', | |
| ] as const |
Summary
Log improved migration errors