lint: evaluate schema linters against post-state#840
Merged
Conversation
…lse positives has_timestamp, has_float, and zero_date previously walked existingTables unconditionally, so a declarative diff or ALTER MODIFY/CHANGE/DROP that fixed a problematic column still produced a warning for the pre-state. Extracts the post-state helper that type_pedantic already used into a shared utility (PostState, PreStateColumns) and reworks the three linters to iterate the after-image. has_timestamp preserves its Warning/Error severity split by consulting the pre-state for untouched columns.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes false positives in schema linters by evaluating columns against a synthesized post-migration (“after image”) schema rather than iterating the pre-state existingTables directly, particularly for ALTERs that drop or convert problematic columns.
Changes:
- Introduces a shared
PostStateschema synthesizer (plus related helpers) for applying relevant CREATE/ALTER effects deterministically. - Updates
has_timestamp,has_float, andzero_dateto lint the post-state schema (withhas_timestamppreserving Warning vs Error semantics via pre-state lookups). - Updates and adds tests, including a regression test for TIMESTAMP→DATETIME conversions in declarative diffs.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/lint/post_state.go | Adds shared post-state schema builder and helpers for tracking pre-state columns / changed columns. |
| pkg/lint/lint_zero_date.go | Switches linter to iterate post-state schema (avoids pre-state false positives). |
| pkg/lint/lint_type_pedantic.go | Replaces private post-state builder with shared PostState. |
| pkg/lint/lint_has_timestamp.go | Reworks TIMESTAMP linting to evaluate post-state and compute severity using pre-state + change tracking. |
| pkg/lint/lint_has_timestamp_test.go | Updates expectations for post-state semantics and adds a regression test. |
| pkg/lint/lint_has_float.go | Reworks FLOAT/DOUBLE linting to evaluate post-state schema and adjust messaging based on change tracking. |
| pkg/lint/lint_has_float_test.go | Updates a complex scenario test to align with post-state behavior (renamed-away columns no longer flagged). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The previous post-state refactor collapsed ADD COLUMN and MODIFY/CHANGE into a single addedOrModified set, so newly-added FLOAT/DOUBLE columns were emitted as "modified to use floating-point data type" — confusing phrasing for what is actually a brand-new column. Tracks MODIFY/CHANGE in a separate columnsModifiedInChanges helper and selects message wording by (pre-state existence, modified flag): - ADD COLUMN or column inside a new CREATE TABLE → "New column …" - MODIFY / CHANGE COLUMN on a pre-existing column → "… modified to …" - Pre-existing untouched FLOAT/DOUBLE → "… uses …" Adds positive/negative assertions on the ADD COLUMN test so this can't regress silently again.
aparajon
approved these changes
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #839.
Summary
buildPostStatehelper out oflint_type_pedantic.gointo a shared utility (PostState,PreStateColumns, plus internalapplyAlterand friends).has_timestamp,has_float, andzero_dateto iterate the post-state view of the schema instead ofexistingTablesdirectly. ALTERs that drop or convert a problematic column no longer false-positive against the pre-state.has_timestamppreserves its Warning (legacy untouched) vs Error (new or modified) severity split by consulting the pre-state when scoring each post-state TIMESTAMP column.type_pedanticswitches to the shared helpers; behavior unchanged.Test plan
go test ./pkg/lint/ -count=1— passesgo test ./pkg/migration/ -run TestLint -count=1— passesTestHasTimestampLinter_DeclarativeDiff_TimestampToDatetime_NoFalsePositive) for the reported case.has_timestamptests and onehas_floattest that encoded the buggy "warn even when fixed" behavior were updated to assert the correct post-state semantics.