feat: restore csv-to-pg package and upgrade to @pgsql/utils #473
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat: restore csv-to-pg package and upgrade to @pgsql/utils
Summary
Restores the
csv-to-pgpackage that was removed in commit 1c563fc (June 2025) and upgrades it from the deprecatedpg-astlibrary to@pgsql/utilsfor latest AST tooling compatibility.Key changes:
pg-astto@pgsql/utils(e.g.,ast.ResTarget()→nodes.resTarget())str→sval,val→ival/fval/sval)ast.Null()tonodes.aConst({ isnull: true })@pgsql/types@^17.6.2,@pgsql/utils@^17.8.3,pgsql-deparser@^17.12.2Updates since last revision
Robustness improvements for CSV to INSERT conversion:
makeLocation()to allow valid 0 coordinates - Changed from falsy check (!longitude || !latitude) to explicit null/undefined checks. Previously, coordinates at 0,0 (e.g., Gulf of Guinea) would incorrectly become NULL.nodes.string({sval: 'TRUE'})tonodes.aConst({ boolval: ast.boolean({ boolval: true }) })for correct AST structure.escapeArrayElement()function handles NULL, quotes, backslashes, commas, braces, and whitespace intext[]values.NULL,null,\N,NA,N/A,n/a,#N/A, and empty strings.required?: booleanoption in field config. When true, throwsValidationErrorwith field name, raw value, expected type, and reason instead of silently returning NULL.makeBoundingBox()now validates exactly 4 numeric parts and coordinate ranges (longitude: -180 to 180, latitude: -90 to 90).Review & Testing Checklist for Human
'TRUE'/'FALSE'toboolvalis significant. Test thatINSERT INTO ... VALUES (TRUE, FALSE)deparses correctly, not as string literals.makeLocation(0, 0)producesst_setsrid(st_makepoint(0, 0), 4326)not NULL.["a,b", "c{d}", "e\"f", ""]should produce valid PostgreSQL array literals.2025-01-15T10:30:00Z), date-only (2025-01-15), and epoch timestamps work correctly.{ type: 'text', required: true }throwsValidationErrorfor NULL/empty values.Recommended test plan:
Notes
This PR unblocks the export CLI feature that was broken due to
ast.ResTarget is not a functionerrors. The csv-to-pg package is used bypgpm/core/src/export/export-meta.tsto generate INSERT statements from database rows.Link to Devin run: https://app.devin.ai/sessions/77df3b12408140e597019f53283de49c
Requested by: Dan Lynch (@pyramation)