Repository navigation
Fix precision-only numeric migration snapshot churn - #4065
Merged
Merged
Conversation
Render the implicit zero scale consistently so precision-only numeric mappings round-trip through migration snapshots without false model changes. Fixes #3521 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d1e2613f-c5cc-43a1-b528-ba712584e442
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The narrow normalization preserves numeric semantics and has focused regression coverage, with no blocking issues identified.
No open issues 🎉
What changed in this PR
Fixes false pending-model-change errors and migration churn by consistently rendering precision-only numeric mappings as numeric(p,0).
Changes:
- Normalizes decimal and BigInteger mappings without changing explicit scales or unconstrained numeric types.
- Adds regression coverage for snapshot comparisons, nullable
[Precision(9)], and store-type facet precedence.
| File | Description |
|---|---|
| test/EFCore.PG.Tests/Storage/NpgsqlTypeMappingSourceTest.cs | Tests numeric normalization, round trips, and facet precedence. |
| test/EFCore.PG.Tests/Migrations/NpgsqlMigrationsModelDifferTest.cs | Tests snapshot comparisons produce no spurious changes. |
| src/EFCore.PG/Storage/Internal/Mapping/NpgsqlDecimalTypeMapping.cs | Renders implicit zero scale for decimal mappings. |
| src/EFCore.PG/Storage/Internal/Mapping/NpgsqlBigIntegerTypeMapping.cs | Applies the same normalization to BigInteger mappings. |
Review effort: Balanced
Preserve runtime numeric type names and omit only inferred precision-only numeric column types from migration snapshots. Verify generated snapshots compile and round-trip, while retaining explicit column types and scales. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d1e2613f-c5cc-43a1-b528-ba712584e442
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d1e2613f-c5cc-43a1-b528-ba712584e442
Move coverage into NpgsqlAnnotationCodeGeneratorTest and directly assert column-type fluent API generation. Remove dynamic snapshot compilation, its model/context scaffolding, and PreserveCompilationContext. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d1e2613f-c5cc-43a1-b528-ba712584e442
This was referenced Oct 21, 2026
roji
added a commit
that referenced
this pull request
Oct 21, 2026
Backport the final net diff of #4065 (820a869). Omit only inferred numeric(p) snapshot column types when precision is configured without scale; preserve explicit types, scales, and runtime mappings. Fixes #3521 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7bfcfb8a-2670-41a1-9d15-97b9557aaee0
roji
added a commit
that referenced
this pull request
Oct 21, 2026
Backport the final net diff from #4065 for #3521. Omit only inferred precision-only numeric column types during annotation generation; retain explicit column types and scales. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6cc44be3-a355-4562-84ca-b67d34a171a5
roji
added a commit
that referenced
this pull request
Oct 21, 2026
Backport the final net diff of #4065 (820a869) for #3521. Omit only inferred precision-only numeric column types during snapshot generation; leave explicit types, scales, and runtime mappings unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 12f9ca8d-c1bf-46b0-bb94-40fe18290c21
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.
Summary
Precision-only numeric properties generate
numeric(p), but reloading that store type from a migration snapshot supplies PostgreSQL's implicit zero scale and producesnumeric(p,0). This creates spuriousAlterColumnoperations and false pending-model-change errors.In snapshot generation, omit the inferred
.HasColumnType("numeric(p)")when precision is configured without a scale. Retain.HasPrecision(p)so reloading reconstructs the same mapping as the original model. Explicitly configured column types and scales are preserved.This is a design-time-only fix: runtime type mappings and SQL type-name rendering remain unchanged. Existing affected snapshots require one regeneration; subsequently generated snapshots round-trip without continuous pending changes.
Focused regression coverage in
NpgsqlAnnotationCodeGeneratorTestdirectly asserts column-type fluent API generation for precision-only nullable decimal properties, explicit zero/nonzero scales, and explicitly configured numeric column types. No dynamic compilation or test-project configuration changes are needed.Fixes #3521