Skip to content

fix: use key-order-independent comparison in equals methods#467

Merged
mmkal merged 2 commits into
mmkal:mainfrom
felamaslen:main
Apr 8, 2026
Merged

fix: use key-order-independent comparison in equals methods#467
mmkal merged 2 commits into
mmkal:mainfrom
felamaslen:main

Conversation

@felamaslen

Copy link
Copy Markdown
Contributor

Closes #466

Inspected.equals(), ColumnInfo.equals(), and PostgreSQL.equals() all used JSON.stringify for comparison, which is sensitive to object key order. When two databases have the same table columns in different physical order (e.g. due to migrations adding columns at different times), the columns object serialises differently, causing the table to appear "modified". This cascades through add_dependents_for_modified to spuriously drop and recreate dependent views — even when the views themselves are semantically identical and explicitly list their columns.

The fix replaces JSON.stringify comparisons with the existing isEqual utility, which sorts object keys before comparing.

Views using SELECT * are still correctly recreated, since Postgres expands SELECT * into the physical column order, producing genuinely different view definitions.

`Inspected.equals()`, `ColumnInfo.equals()`, and `PostgreSQL.equals()`
all used `JSON.stringify` for comparison, which is sensitive to object
key order. When two databases have the same table columns in different
physical order, the `columns` object serialises differently, making the
table appear modified. This cascades through `add_dependents_for_modified`
to spuriously drop and recreate dependent views, even when the views
themselves are identical.

Replace `JSON.stringify` comparisons with the existing `isEqual` utility,
which sorts keys before comparing.
…diff

fix: use key-order-independent comparison in `equals` methods
@vercel

vercel Bot commented Apr 1, 2026

Copy link
Copy Markdown

@felamaslen is attempting to deploy a commit to the mmkal Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Apr 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pgkit Ready Ready Preview, Comment Apr 2, 2026 10:35am

Request Review

@mmkal

mmkal commented Apr 2, 2026

Copy link
Copy Markdown
Owner

Thank you, this definitely looks sensible. I've approved the workflow to see if all the existing tests pass too.

@felamaslen

Copy link
Copy Markdown
Contributor Author

@mmkal any progress here?

@mmkal mmkal merged commit d77bb45 into mmkal:main Apr 8, 2026
3 checks passed
@mmkal

mmkal commented Apr 8, 2026

Copy link
Copy Markdown
Owner

@felamaslen merged but having some trouble publishing, will let you know when I hear from npm support

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.

Spurious view drop/recreate when table column order differs between databases

2 participants