Skip to content

Strip psql meta-commands from schema files (fixes #4065) - #4390

Merged
kyleconroy merged 1 commit into
mainfrom
claude/add-comment-prefix-regex-HeATn
Apr 19, 2026
Merged

kyleconroy merged 1 commit into
mainfrom
claude/add-comment-prefix-regex-HeATn

Conversation

@kyleconroy

Copy link
Copy Markdown
Collaborator

pg_dump 17.6+ (backported to 13.22, 14.19, 15.14, 16.10) emits
\restrict/\unrestrict meta-commands that are valid psql syntax but not
valid SQL, causing sqlc to fail when parsing schema.sql from pg_dump.

Add a regex-based preprocessor in the migrations package that strips
any line starting with a psql meta-command (<command>), and call it
from parseCatalog after RemoveRollbackStatements. Extend the pg_dump
end-to-end schema fixture with \restrict/\unrestrict lines so TestReplay
exercises this path.

pg_dump 17.6+ (backported to 13.22, 14.19, 15.14, 16.10) emits
\restrict/\unrestrict meta-commands that are valid psql syntax but not
valid SQL, causing sqlc to fail when parsing schema.sql from pg_dump.

Add a regex-based preprocessor in the migrations package that strips
any line starting with a psql meta-command (\<command>), and call it
from parseCatalog after RemoveRollbackStatements. Extend the pg_dump
end-to-end schema fixture with \restrict/\unrestrict lines so TestReplay
exercises this path.
@kyleconroy
kyleconroy merged commit 394bdc7 into main Apr 19, 2026
12 checks passed
@kyleconroy
kyleconroy deleted the claude/add-comment-prefix-regex-HeATn branch April 19, 2026 15:46
ethanndickson added a commit to coder/sqlc that referenced this pull request May 8, 2026
This pulls in 78 upstream commits since coder/sqlc's prior fork point
(b807fe9), most importantly:

* sqlc-dev#4390: strip \restrict / \unrestrict psql meta-commands
  from schema files (fixes sqlc-dev#4065 / coder/internal#965).
* sqlc-dev#4378: upgrade Go toolchain to 1.26.2.
* Various dependency bumps and parser improvements.

Conflict resolution:

* All content conflicts were import-path collisions — our renamed
  imports (github.com/coder/sqlc) versus upstream's additions of new
  sqlc-dev/sqlc imports. Resolved by taking upstream's side, then
  re-applying the global rename across .go and go.mod files (including
  newly-added upstream files that auto-merged).
* internal/sqltest/pgx.go: accepted upstream deletion (removed in
  sqlc-dev#4379, 'Remove github.com/jackc/pgx/v4 dependency').
ethanndickson added a commit to coder/sqlc that referenced this pull request May 8, 2026
This pulls in 78 upstream commits since coder/sqlc's prior fork point
(b807fe9), most importantly:

* sqlc-dev#4390: strip \restrict / \unrestrict psql meta-commands
  from schema files (fixes sqlc-dev#4065 / coder/internal#965).
* sqlc-dev#4378: upgrade Go toolchain to 1.26.2.
* Various dependency bumps and parser improvements.

Conflict resolution:

* All content conflicts were import-path collisions — our renamed
  imports (github.com/coder/sqlc) versus upstream's additions of new
  sqlc-dev/sqlc imports. Resolved by taking upstream's side, then
  re-applying the global rename across .go and go.mod files (including
  newly-added upstream files that auto-merged).
* internal/sqltest/pgx.go: accepted upstream deletion (removed in
  sqlc-dev#4379, 'Remove github.com/jackc/pgx/v4 dependency').
ethanndickson added a commit to coder/sqlc that referenced this pull request May 8, 2026
This pulls in 78 upstream commits since coder/sqlc's prior fork point
(b807fe9), most importantly:

* sqlc-dev#4390: strip \restrict / \unrestrict psql meta-commands
  from schema files (fixes sqlc-dev#4065 / coder/internal#965).
* sqlc-dev#4378: upgrade Go toolchain to 1.26.2.
* Various dependency bumps and parser improvements.

Conflict resolution:

* All content conflicts were import-path collisions — our renamed
  imports (github.com/coder/sqlc) versus upstream's additions of new
  sqlc-dev/sqlc imports. Resolved by taking upstream's side, then
  re-applying the global rename across .go and go.mod files (including
  newly-added upstream files that auto-merged).
* internal/sqltest/pgx.go: accepted upstream deletion (removed in
  sqlc-dev#4379, 'Remove github.com/jackc/pgx/v4 dependency').
ethanndickson added a commit to coder/coder that referenced this pull request May 11, 2026
Closes coder/internal#965.

* Bump the coder/sqlc fork pin to 337309b on coder/sqlc:main, the merge
  of upstream v1.31.1 onto our two-patch fork (coder/sqlc#6). Updated in
  three places that pin the fork SHA: flake.nix (sqlc-custom),
  .github/actions/setup-sqlc/action.yaml (used by CI), and the
  dogfood/coder/ubuntu-{22,26}.04 Dockerfiles. v1.31.1 includes
  sqlc-dev/sqlc#4390, the upstream fix for psql \restrict / \unrestrict
  meta-commands that recent pg_dump releases (13.22+, 14.19+, 15.14+,
  16.10+, 17.6+) emit, plus an upgrade to Go 1.26.2.
* Reset sqlc-custom's sha256 and vendorHash to pkgs.lib.fakeSha256. Nix
  will fail with the real hashes on first build, per the existing
  comment block above the derivation.
* Drop the temporary pg_dump docker pin introduced in #19696. Local
  pg_dump (13+) and the docker fallback are both fine again now that
  sqlc parses meta-commands.
* Strip \restrict / \unrestrict lines in dbtestutil.normalizeDump so
  scripts/migrate-test's schema-equality comparison is stable across
  pg_dump versions (the token in those lines is randomized per run).
  Add TestNormalizeDumpStripsRestrict to lock the behavior in.
* Re-run make gen, picking up the v1.31.1 stamp and one upstream
  correctness fix in DeleteLicense (sqlc-dev/sqlc#4383: don't shadow the
  input parameter when scanning a single-column return).
ethanndickson added a commit to coder/coder that referenced this pull request May 13, 2026
Closes coder/internal#965.

* Bump the coder/sqlc fork pin to 337309b on coder/sqlc:main, the merge
  of upstream v1.31.1 onto our two-patch fork (coder/sqlc#6). Updated in
  three places that pin the fork SHA: flake.nix (sqlc-custom),
  .github/actions/setup-sqlc/action.yaml (used by CI), and the
  dogfood/coder/ubuntu-{22,26}.04 Dockerfiles. v1.31.1 includes
  sqlc-dev/sqlc#4390, the upstream fix for psql \restrict / \unrestrict
  meta-commands that recent pg_dump releases (13.22+, 14.19+, 15.14+,
  16.10+, 17.6+) emit, plus an upgrade to Go 1.26.2.
* Reset sqlc-custom's sha256 and vendorHash to pkgs.lib.fakeSha256. Nix
  will fail with the real hashes on first build, per the existing
  comment block above the derivation.
* Drop the temporary pg_dump docker pin introduced in #19696. Local
  pg_dump (13+) and the docker fallback are both fine again now that
  sqlc parses meta-commands.
* Strip \restrict / \unrestrict lines in dbtestutil.normalizeDump so
  scripts/migrate-test's schema-equality comparison is stable across
  pg_dump versions (the token in those lines is randomized per run).
  Add TestNormalizeDumpStripsRestrict to lock the behavior in.
* Re-run make gen, picking up the v1.31.1 stamp and one upstream
  correctness fix in DeleteLicense (sqlc-dev/sqlc#4383: don't shadow the
  input parameter when scanning a single-column return).
ethanndickson added a commit to coder/coder that referenced this pull request May 13, 2026
…5105)

Closes coder/internal#965

Recent `pg_dump` patch releases (13.22+ / 14.19+ / 15.14+ / 16.10+ /
17.6+) emit `\restrict` / `\unrestrict` psql meta-commands at the head
and tail of schema dumps. These broke both `sqlc` and our
`scripts/migrate-test` schema-equality check. PR #19696 worked around it
by pinning `pg_dump` to a Docker image.

This change unpins the workaround now that `sqlc` handles the
meta-commands:

* Bumps the coder/sqlc fork pin to [`337309b` on
coder/sqlc:main](coder/sqlc@337309b),
the merge of upstream v1.31.1 (coder/sqlc#6). v1.31.1 includes
[sqlc-dev/sqlc#4390](sqlc-dev/sqlc#4390), the
upstream `\restrict` / `\unrestrict` parser fix. Updated in three places
that pin the fork SHA: `flake.nix` (`sqlc-custom`),
`.github/actions/setup-sqlc/action.yaml`, and the
`dogfood/coder/ubuntu-{22,26}.04` Dockerfiles. The flake's `sha256` /
`vendorHash` are reset to `pkgs.lib.fakeSha256`; Nix will surface the
real hashes on first build, per the existing comment block.
* Reverts #19696's Docker pin in `coderd/database/dbtestutil/db.go`.
Local `pg_dump` (13+) and the `postgres:13` Docker fallback both work
again.
* Strips `\restrict` / `\unrestrict` lines in `normalizeDump` so
`scripts/migrate-test`'s schema comparison is stable across `pg_dump`
versions (the token in those lines is randomized per run).
`TestNormalizeDumpStripsRestrict` locks the behavior in.
* Regenerates with v1.31.1, picking up the version stamp and one
upstream correctness fix in `DeleteLicense`
([sqlc-dev/sqlc#4383](sqlc-dev/sqlc#4383): don't
shadow the input parameter when scanning a single-column return).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants