Skip to content

linter: fix adding-not-nullable-field for pg >= 12 with validated CHECK#910

Open
reteps wants to merge 1 commit intosbdchd:masterfrom
reteps:fix/adding-not-nullable-field-pg12
Open

linter: fix adding-not-nullable-field for pg >= 12 with validated CHECK#910
reteps wants to merge 1 commit intosbdchd:masterfrom
reteps:fix/adding-not-nullable-field-pg12

Conversation

@reteps
Copy link

@reteps reteps commented Feb 3, 2026

Summary

Fixes #628

For PostgreSQL 12+, when there's a validated CHECK constraint that ensures a column IS NOT NULL (e.g., CHECK (col IS NOT NULL)), the subsequent SET NOT NULL operation can skip the full table scan because PostgreSQL can use the validated constraint to verify the invariant.

This fix tracks CHECK constraints with NOT VALID that check for column IS NOT NULL, and after they are validated via VALIDATE CONSTRAINT, allows the SET NOT NULL without warning.

Changes

  • Track ADD CONSTRAINT ... CHECK (column IS NOT NULL) NOT VALID statements
  • Track VALIDATE CONSTRAINT for those constraints
  • For pg >= 12, skip the adding-not-nullable-field warning when SET NOT NULL is used on a column with a validated CHECK constraint

Test plan

  • Added test for pg 16 with validated CHECK constraint (should pass)
  • Added test for pg 12 with validated CHECK constraint (should pass)
  • Added test for pg 11 with validated CHECK constraint (should fail - feature not available)
  • Added test for pg 12 without validated CHECK constraint (should fail)
  • Added test for pg 12 with CHECK but not yet validated (should fail)
  • Added test for pg 12 with CHECK on different column (should fail)
  • All existing tests pass

🤖 Generated with Claude Code

For PostgreSQL 12+, when there's a validated CHECK constraint that
ensures a column IS NOT NULL (e.g., `CHECK (col IS NOT NULL)`), the
subsequent `SET NOT NULL` operation can skip the full table scan.

This fix tracks CHECK constraints with NOT VALID that check for
`column IS NOT NULL`, and after they are validated via VALIDATE
CONSTRAINT, allows the SET NOT NULL without warning.

Fixes sbdchd#628

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@netlify
Copy link

netlify bot commented Feb 3, 2026

👷 Deploy request for squawkhq pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 1da42ae

@reteps
Copy link
Author

reteps commented Feb 3, 2026

Disclaimer: I have no idea what I am doing here, but the fix Claude put up looks sensible. If you want to close this out, or use this as a starting point, feel free.

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.

adding-not-nullable-field not succeeding for pg >= 12

1 participant