Skip to content

Comments

fix: parentheses handling in CHECK constraint normalization#35

Merged
tianzhou merged 1 commit intopgplex:mainfrom
grachevko:main
Sep 23, 2025
Merged

fix: parentheses handling in CHECK constraint normalization#35
tianzhou merged 1 commit intopgplex:mainfrom
grachevko:main

Conversation

@grachevko
Copy link
Contributor

This PR fixes a critical issue in the CHECK constraint normalization logic where improperly balanced parentheses could lead to incorrect expression parsing.

Problem Fixed

The previous implementation would remove ALL outer parentheses without checking if they were properly balanced or part of a larger expression structure.

This break expressions like: CHECK ((code >= 0) AND (code <= 255))
Previous: CHECK (code >= 0) AND (code <= 255)
Current: CHECK (code >= 0 AND code <= 255)

@grachevko grachevko changed the title fix: Fix parentheses handling in CHECK constraint normalization fix: parentheses handling in CHECK constraint normalization Sep 23, 2025
Copy link
Contributor

@tianzhou tianzhou left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

Let's add a separate create_table/add_check test case to verify this.

@grachevko grachevko force-pushed the main branch 3 times, most recently from d533d19 to 6fa2fbb Compare September 23, 2025 15:50
@grachevko
Copy link
Contributor Author

@tianzhou check please

@tianzhou
Copy link
Contributor

tianzhou commented Sep 23, 2025

@grachevko Looks like the new test fails. Please check

You can run

PGSCHEMA_TEST_FILTER="create_table/add_check" go test -v ./internal/diff -run TestDiffFromFiles

…tion

- Add balanced parentheses validation before removing outer parentheses
- Prevent incorrect normalization of complex expressions with nested parentheses
- Improve robustness of CHECK constraint parsing logic
@grachevko
Copy link
Contributor Author

➜  pgschema git:(main) ✗ PGSCHEMA_TEST_FILTER="create_table/add_check" go test -v ./internal/diff -run TestDiffFromFiles
=== RUN   TestDiffFromFiles
=== RUN   TestDiffFromFiles/create_table_add_check
--- PASS: TestDiffFromFiles (0.01s)
    --- PASS: TestDiffFromFiles/create_table_add_check (0.01s)
PASS
ok      github.com/pgschema/pgschema/internal/diff      0.020s

@grachevko grachevko requested a review from tianzhou September 23, 2025 16:46
Copy link
Contributor

@tianzhou tianzhou left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the fix!

@tianzhou tianzhou merged commit 7af6352 into pgplex:main Sep 23, 2025
1 check passed
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.

2 participants