Skip to content

Fix precision-only numeric migration snapshot churn - #4065

Merged
roji merged 4 commits into
mainfrom
roji-fix-decimal-precision-migration-churn
Oct 21, 2026
Merged

roji merged 4 commits into
mainfrom
roji-fix-decimal-precision-migration-churn

Conversation

@roji

@roji roji commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Precision-only numeric properties generate numeric(p), but reloading that store type from a migration snapshot supplies PostgreSQL's implicit zero scale and produces numeric(p,0). This creates spurious AlterColumn operations 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 NpgsqlAnnotationCodeGeneratorTest directly 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

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
Copilot AI balanced review requested due to automatic review settings October 21, 2026 15:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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
Copilot AI balanced review requested due to automatic review settings October 21, 2026 15:20
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d1e2613f-c5cc-43a1-b528-ba712584e442

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The narrowly scoped design-time fix preserves explicit configuration and includes targeted regression coverage; tests were not executed.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 21, 2026 15:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Static review found no blocking issues in the narrowly scoped fix and regression coverage; tests were not run.

No open issues 🎉

Review effort: Balanced

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
Copilot AI balanced review requested due to automatic review settings October 21, 2026 15:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Static review found no blocking issues in the narrowly scoped fix and regression coverage; tests were not executed.

No open issues 🎉

Review effort: Balanced

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
@roji
roji merged commit 6e86acd into main Oct 21, 2026
15 checks passed
@roji
roji deleted the roji-fix-decimal-precision-migration-churn branch October 21, 2026 15:54
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.

PrecisionAttribute on Decimal parameter causes false positive for PendingModelChangesWarning exception

2 participants