Skip to content

fix(migrations): stop migrator.up() from churning a snapshot that matches the DB#7804

Merged
B4nan merged 1 commit into
masterfrom
fix/7798-skip-snapshot-rewrite-when-unchanged
May 29, 2026
Merged

fix(migrations): stop migrator.up() from churning a snapshot that matches the DB#7804
B4nan merged 1 commit into
masterfrom
fix/7798-skip-snapshot-rewrite-when-unchanged

Conversation

@B4nan
Copy link
Copy Markdown
Member

@B4nan B4nan commented May 29, 2026

Follow-up to #7803 (now merged) for the Postgres side of #7798.

migration:create writes .snapshot-<db>.json from entity metadata, while migration:up/migration:down rewrite it from DB introspection. Even when the migrated database still matches the snapshot, the two serializations diverge in cosmetic-only ways the SchemaComparator already treats as equal:

  • current_timestampCURRENT_TIMESTAMP (default casing)
  • (coalesce(...) ...) STORED(COALESCE(...) ...) stored (generated-expr reformatting)
  • partial-where clauses rewrapped with explicit casts (status = 'PENDING'(status)::text = 'PENDING'::text)
  • native-enum mappedType, index gin method, check definition format

So every migrator.up() produced a noisy git diff on the snapshot even with no real schema change (the reported symptom). These can't all be normalized byte-for-byte in toJSON() — Postgres rewrites the stored expressions unpredictably.

Instead, skip the rewrite when the introspected schema doesn't differ from the on-disk snapshot in any way the comparator turns into SQL. The file then stays exactly as authored by migration:create. A real schema change (or a stale snapshot) still rewrites it as before — the existing sqlite up/down snapshot test is updated to assert this no-churn guarantee.

Closes #7798

…ches the DB

`migration:create` writes `.snapshot-<db>.json` from entity metadata, while
`migration:up`/`migration:down` rewrite it from DB introspection. Even when the
migrated database still matches the snapshot, the two serializations diverge in
cosmetic-only ways the comparator already treats as equal (default casing,
generated-/where-expression reformatting, native-enum mapped type, index method,
check definition format), so every `up()` produced a noisy snapshot diff.

Skip the rewrite when the introspected schema does not differ from the on-disk
snapshot in any way the comparator turns into SQL — the file then stays exactly
as authored by `migration:create`. A real schema change (or a stale snapshot)
still rewrites it as before.

Refs #7798
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.64%. Comparing base (a972992) to head (4a33621).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #7804    +/-   ##
========================================
  Coverage   99.64%   99.64%            
========================================
  Files         285      285            
  Lines       29664    29671     +7     
  Branches     8119     8291   +172     
========================================
+ Hits        29559    29566     +7     
  Misses         98       98            
  Partials        7        7            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@B4nan B4nan enabled auto-merge (squash) May 29, 2026 12:55
@B4nan B4nan merged commit 3f1297c into master May 29, 2026
25 of 26 checks passed
@B4nan B4nan deleted the fix/7798-skip-snapshot-rewrite-when-unchanged branch May 29, 2026 12:58
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.

orm.migrator.up() rewrites snapshot incorrectly

1 participant