Skip to content

Fix Postgres default parsing for pg_catalog.nextval(...)#5802

Open
Lukasdoe wants to merge 1 commit intoprisma:mainfrom
Lukasdoe:fix/postgres-pg-catalog-nextval
Open

Fix Postgres default parsing for pg_catalog.nextval(...)#5802
Lukasdoe wants to merge 1 commit intoprisma:mainfrom
Lukasdoe:fix/postgres-pg-catalog-nextval

Conversation

@Lukasdoe
Copy link
Copy Markdown

@Lukasdoe Lukasdoe commented Apr 8, 2026

This fixes a small parsing gap in Postgres introspection.

The parser already handled nextval(), but not schema-qualified calls like pg_catalog.nextval(). In some setups, the database can return the qualified form (not specified), so sequence defaults could be missed.

This PR updates the parser to recognize both forms and adds a test.

Copilot AI review requested due to automatic review settings April 8, 2026 14:50
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b9a1890d-d533-4eb9-8242-23f60d386dc7

📥 Commits

Reviewing files that changed from the base of the PR and between f811693 and 7a130e3.

📒 Files selected for processing (1)
  • schema-engine/sql-schema-describer/src/postgres/default.rs

Summary by CodeRabbit

  • Bug Fixes

    • PostgreSQL integer defaults using nextval(...) are now correctly recognized whether unqualified or schema-qualified as pg_catalog.nextval; other schema-qualified variants are not treated as DB-generated sequence defaults.
  • Tests

    • Added tests to verify correct parsing of schema-qualified sequence defaults and rejection of non-standard qualified forms.

Walkthrough

Postgres integer default parsing updated to recognize nextval(...) as a sequence default when unqualified or schema-qualified as pg_catalog.nextval(...). Logic now checks for a dot-qualified pg_catalog.nextval pattern and returns early for non-matching identifiers. Tests added for both matching and non-matching cases.

Changes

Cohort / File(s) Summary
PostgreSQL Default Parsing
schema-engine/sql-schema-describer/src/postgres/default.rs
Accept nextval(...) as a valid sequence default for both unqualified nextval and schema-qualified pg_catalog.nextval. Introduced inline check for the . + identifier pattern and early returns for non-nextval identifiers. Added unit tests validating pg_catalog.nextval('first_sequence'::regclass) parses as a sequence default and public.nextval(...) does not.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix Postgres default parsing for pg_catalog.nextval(...)' clearly and concisely summarizes the main change: adding support for schema-qualified Postgres sequence defaults.
Description check ✅ Passed The description is directly related to the changeset, explaining the parsing gap, the specific problem, and the solution of supporting both unqualified and schema-qualified nextval forms.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Postgres default-value parser in sql-schema-describer to recognize schema-qualified nextval() calls (e.g. pg_catalog.nextval(...)) so autoincrement/sequence defaults are correctly detected during introspection.

Changes:

  • Extend integer default parsing to accept *.nextval(...) in addition to nextval(...).
  • Add a regression test covering pg_catalog.nextval('...') sequence defaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 8, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@schema-engine/sql-schema-describer/src/postgres/default.rs`:
- Around line 312-327: The qualified-name branch currently accepts any
"<schema>.nextval(...)" by only checking the trailing identifier; change the
logic in the is_nextval computation so that when a Token::Dot is present you
first treat the existing identifier s as the schema and only accept the match if
s.eq_ignore_ascii_case("pg_catalog") AND the following identifier equals
"nextval" (case-insensitive). In other words, inside the Token::Dot arm (where
parser.expect(Token::Dot)? and parser.expect(Token::Identifier) are used)
require s == "pg_catalog" && the next identifier.eq_ignore_ascii_case("nextval")
before returning true for is_nextval.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c3dbbaae-6b6a-4dbe-8cc7-2740814008df

📥 Commits

Reviewing files that changed from the base of the PR and between 75cbdc1 and f811693.

📒 Files selected for processing (1)
  • schema-engine/sql-schema-describer/src/postgres/default.rs

Accept schema-qualified nextval() calls (e.g. pg_catalog.nextval) when parsing Postgres integer defaults, and add coverage in parser tests.
@Lukasdoe Lukasdoe force-pushed the fix/postgres-pg-catalog-nextval branch from f811693 to 7a130e3 Compare April 8, 2026 15:28
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 10, 2026

Merging this PR will not alter performance

✅ 11 untouched benchmarks
⏩ 11 skipped benchmarks1


Comparing Lukasdoe:fix/postgres-pg-catalog-nextval (7a130e3) with main (75cbdc1)

Open in CodSpeed

Footnotes

  1. 11 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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.

3 participants