Skip to content

linter: scope cross-migration SET NOT NULL suppression#1033

Open
reteps wants to merge 4 commits intosbdchd:masterfrom
reteps:scoped-set-not-null
Open

linter: scope cross-migration SET NOT NULL suppression#1033
reteps wants to merge 4 commits intosbdchd:masterfrom
reteps:scoped-set-not-null

Conversation

@reteps
Copy link
Copy Markdown
Contributor

@reteps reteps commented Apr 1, 2026

Summary

  • Previously, an external VALIDATE CONSTRAINT (without a matching ADD CONSTRAINT in the same file) blanket-marked the entire table as safe, suppressing SET NOT NULL warnings for all columns — even unrelated ones
  • Now uses validate+drop pairing: only constraints that are both validated AND dropped in the same file are treated as NOT NULL helpers, and each pair suppresses exactly one SET NOT NULL violation
  • Adds tests for the false-negative cases (unrelated validate, validate without drop)

Test plan

  • cargo test --package squawk-linter -- adding_not_null_field — all 16 tests pass
  • Cross-migration OK tests still pass (validate + set not null + drop pattern)
  • New error tests catch unrelated validate and validate-without-drop cases
  • ./s/lint passes
  • ./s/test passes

🤖 Generated with Claude Code

…op pairs

Previously, an external VALIDATE CONSTRAINT (without a matching
ADD CONSTRAINT in the same file) blanket-marked the entire table as
safe, suppressing SET NOT NULL warnings for all columns. This caused
false negatives when the validated constraint was unrelated to the
column being tightened.

Now, only constraints that are both validated AND dropped in the same
file are treated as NOT NULL helpers. Each validate+drop pair can
suppress one SET NOT NULL violation on that table.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 1, 2026

👷 Deploy request for squawkhq pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 8976d6d

@reteps reteps marked this pull request as ready for review April 1, 2026 19:05
Comment thread crates/squawk_linter/src/rules/adding_not_null_field.rs Outdated
@reteps reteps marked this pull request as draft May 1, 2026 15:03
reteps and others added 3 commits May 1, 2026 10:30
Bundle the related hash sets/maps used for cross-migration NOT NULL
suppression behind a NotNullValidation struct with named methods
(record_validate, is_column_validated, has_external_validate_for, etc.)
so callers don't have to know about the internal representation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

### cross-migration suppression and constraint naming

When the `ADD CONSTRAINT ... NOT VALID` lives in an earlier migration file, the rule looks for a `VALIDATE CONSTRAINT` paired with a `DROP CONSTRAINT` of the same name in the migration that runs `SET NOT NULL` to recognize the safe pattern.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had to explain an edge case here: We can't associate the constraint with a column easily, so we tell the user to use a conventional format for the constraint.

@reteps reteps requested a review from sbdchd May 1, 2026 19:48
@reteps reteps marked this pull request as ready for review May 1, 2026 19:48
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