Title: fix: robustly strip psql meta commands by ignatremizov · Pull Request #4479 · sqlc-dev/sqlc · GitHub
Open Graph Title: fix: robustly strip psql meta commands by ignatremizov · Pull Request #4479 · sqlc-dev/sqlc
X Title: fix: robustly strip psql meta commands by ignatremizov · Pull Request #4479 · sqlc-dev/sqlc
Description: Summary This PR makes PostgreSQL schema preprocessing safer for pg_dump / psql-flavored input without turning sqlc into a psql interpreter. It preserves real PostgreSQL SQL, strips or warns on client-side commands, rejects script semantics that cannot be supported safely, and shares the apply-time schema loading path used by command setup and PostgreSQL sqltest seeding. Changes PostgreSQL schema preprocessing Replace the old line-based PostgreSQL filter with a single-pass state machine that only strips top-level psql meta-commands outside SQL lexical context. Keep explicit coverage of documented psql backslash commands as a reference fixture. See PostgreSQL psql docs Preserve backslashes that appear in valid PostgreSQL SQL, including: string literals, including E'...' quoted identifiers dollar-quoted bodies comments and nested block comments Support the valid \meta ... \\ SQL... separator form and keep trailing SQL intact, including glued and one-sided-whitespace separator forms observed in supported psql versions. Preserve invalid leading \\ input instead of normalizing it into SQL. Handle Unicode dollar-quote tags, identifier-boundary checks, CR/LF normalization, and \copy ... from stdin blocks. Semantic command handling Strip semantic psql commands such as \connect, \copy, \gexec, \i, \ir, \q, \quit, and \r in parse/codegen paths with warnings so users get told when sqlc is ignoring client-side behavior. Reject those same semantic commands in apply/live-DB paths where silently flattening them would be unsafe. Reject psql conditionals (\if, \elif, \else, \endif) instead of pretending to support them. Keep standard_conforming_strings handling as a best-effort parse aid and warn in parse/codegen paths when preprocessing has to approximate session/script semantics rather than emulate psql. Suppress that parse-only approximation warning in apply/live-DB paths because the database executes transaction and session SQL directly there. Rollout across schema-loading paths Apply the shared PostgreSQL preprocessing behavior in: compiler parsing / generate createdb verify managed vet PostgreSQL sqltest seeding Surface preprocessing warnings through the relevant callers instead of keeping them internal to the migration helper. Keep apply/live-DB paths strict so invalid SQL, including dumps that recreate already-present schema objects, still fails with PostgreSQL's normal errors. Follow-up refactor Extract the repeated apply-time glob/read/preprocess/warn loop into schemautil.LoadSchemasForApply(). Reuse that loader across command setup and PostgreSQL sqltest helpers so apply-time behavior stays aligned as preprocessing evolves. Preserve read-only PostgreSQL cache hashing on preprocessed DDL. Do not special-case or rewrite pg_dump public schema DDL; apply-mode callers continue to see PostgreSQL's native behavior. Behavioral impact sqlc is now much more tolerant of pg_dump / psql-flavored PostgreSQL schema files without corrupting valid SQL that happens to contain backslashes. Parse/codegen paths are intentionally permissive with warnings when users are in footgun territory. Apply/live-DB paths stay stricter and reject client-side script behavior that sqlc cannot reproduce safely. This does not try to become a full psql interpreter; full arbitrary client-side script semantics remain out of scope here. Testing go test ./internal/migrations ./internal/compiler ./internal/schemautil ./internal/cmd ./internal/sqltest/... go test ./internal/migrations -coverprofile=/tmp/sqlc-migrations.cover reports 100.0% statement coverage for internal/migrations Related Replaces #4177. Co-authored-by: Andrew Benton andrew@sqlc.dev Addresses gbarr's comment in #4082 which closes #4065
Open Graph Description: Summary This PR makes PostgreSQL schema preprocessing safer for pg_dump / psql-flavored input without turning sqlc into a psql interpreter. It preserves real PostgreSQL SQL, strips or warns on clie...
X Description: Summary This PR makes PostgreSQL schema preprocessing safer for pg_dump / psql-flavored input without turning sqlc into a psql interpreter. It preserves real PostgreSQL SQL, strips or warns on clie...
Opengraph URL: https://github.com/sqlc-dev/sqlc/pull/4479
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:2181a1d9-f0fb-0ddc-0db9-9813caabaa05 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E29A:3F0628:AF0C810:B2886AC:6A50C003 |
| html-safe-nonce | f5afa2dc111d53005bba12410e8635ffd47610dfd6461375cebfbd9ac9c8de00 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjlBOjNGMDYyODpBRjBDODEwOkIyODg2QUM6NkE1MEMwMDMiLCJ2aXNpdG9yX2lkIjoiMjc3NzI5OTMwNzYzMTUyNTg5MSIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | 5c588649aaa7b84c5df33c7622b39e4994146b60ee8c929f355b06621cdbab9b |
| hovercard-subject-tag | pull_request:3838477514 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/sqlc-dev/sqlc/pull/4479/files |
| twitter:image | https://avatars.githubusercontent.com/u/8076691?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/8076691?s=400&v=4 |
| og:image:alt | Summary This PR makes PostgreSQL schema preprocessing safer for pg_dump / psql-flavored input without turning sqlc into a psql interpreter. It preserves real PostgreSQL SQL, strips or warns on clie... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 72b13e0e8d0319acdd27a145cfe73f4f06c791713d0ac4690e41fb68ad28cac0 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/sqlc-dev/sqlc git https://github.com/sqlc-dev/sqlc.git |
| octolytics-dimension-user_id | 136738596 |
| octolytics-dimension-user_login | sqlc-dev |
| octolytics-dimension-repository_id | 193160679 |
| octolytics-dimension-repository_nwo | sqlc-dev/sqlc |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 193160679 |
| octolytics-dimension-repository_network_root_nwo | sqlc-dev/sqlc |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 08e79d53fc070870d5b168356afebb1e286a2ffe |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width