Skip to content

lint: evaluate schema linters against post-state#840

Merged
morgo merged 2 commits into
block:mainfrom
morgo:lint-post-state-fix
May 12, 2026
Merged

lint: evaluate schema linters against post-state#840
morgo merged 2 commits into
block:mainfrom
morgo:lint-post-state-fix

Conversation

@morgo
Copy link
Copy Markdown
Collaborator

@morgo morgo commented May 12, 2026

Closes #839.

Summary

  • Lifts the buildPostState helper out of lint_type_pedantic.go into a shared utility (PostState, PreStateColumns, plus internal applyAlter and friends).
  • Reworks has_timestamp, has_float, and zero_date to iterate the post-state view of the schema instead of existingTables directly. ALTERs that drop or convert a problematic column no longer false-positive against the pre-state.
  • has_timestamp preserves its Warning (legacy untouched) vs Error (new or modified) severity split by consulting the pre-state when scoring each post-state TIMESTAMP column.
  • type_pedantic switches to the shared helpers; behavior unchanged.

Test plan

  • go test ./pkg/lint/ -count=1 — passes
  • go test ./pkg/migration/ -run TestLint -count=1 — passes
  • Added a regression test (TestHasTimestampLinter_DeclarativeDiff_TimestampToDatetime_NoFalsePositive) for the reported case.
  • Five pre-existing has_timestamp tests and one has_float test that encoded the buggy "warn even when fixed" behavior were updated to assert the correct post-state semantics.

…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.
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

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 PostState schema synthesizer (plus related helpers) for applying relevant CREATE/ALTER effects deterministically.
  • Updates has_timestamp, has_float, and zero_date to lint the post-state schema (with has_timestamp preserving 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.

Comment thread pkg/lint/lint_has_float.go
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.
@morgo morgo merged commit cc8c714 into block:main May 12, 2026
11 checks passed
@morgo morgo deleted the lint-post-state-fix branch May 12, 2026 14:09
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.

Schema linters (has_timestamp, has_float, zero_date) false-positive on type-conversion ALTERs

3 participants