Repository navigation
feat(diff): case-insensitive table matching and row hashing for cross-engine diffs - #127
Merged
Merged
Conversation
Cross-engine data diffs (e.g. PostgreSQL -> Oracle) silently reported
"No data differences found" because identifier case folding differs
between engines: PostgreSQL stores unquoted names lower-case ("customers")
while Oracle stores them upper-case ("CUSTOMERS"). Table matching and the
row hash keyed on the raw identifier, so no tables matched, zero rows were
compared, and real missing/changed rows went undetected — a dangerous
false negative for a migration-verification tool.
Fix the data-diff path to compare on a canonical (case-folded) identifier
while preserving the real identifier for SQL generation, since quoted
identifiers are case-sensitive in most engines (notably Oracle):
- schema.CanonicalIdent: case/whitespace-normalized identifier for matching
- content.orderedColumns: order columns by canonical name so both engines
produce a comparable column sequence
- content.hashRow: emit canonical column names so identical row data hashes
equal regardless of identifier case
- content.BuildDataDiff: match tables by canonical name, look up hashes by
each side's real name, label output with the prod-side name
- runDiff: build the shared-table set by canonical name so both sides hash
Schema drift (legitimate cross-engine type differences such as integer vs
number, varchar vs varchar2) is still reported honestly and unchanged.
gen-pack/apply SQL generation is unaffected and remains a follow-up for
cross-engine migration packs.
Verified end-to-end against live PostgreSQL and Oracle XE containers:
the diff now reports rows missing in Oracle (removed_keys) and value
drift (updated_keys) correctly.
Tests:
- schema.TestCanonicalIdent (+ cross-engine match invariant)
- content.TestHashTable_CrossEngineCaseInsensitive
- content.TestBuildDataDiff_CaseInsensitiveTableMatch
Contributor
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Problem
Cross-engine data diffs (e.g. PostgreSQL → Oracle) silently reported "No data differences found", even when the target was missing rows or had drifted values.
Root cause: engines fold unquoted identifier case differently — PostgreSQL stores
customers, Oracle storesCUSTOMERS. Table matching and the row hash keyed on the raw identifier, so:customers≠CUSTOMERS)For a migration-verification tool, that's a dangerous false negative.
Fix
Compare on a canonical (case-folded) identifier, while preserving the real identifier for SQL generation — quoted identifiers are case-sensitive in most engines (notably Oracle), so lower-casing a real Oracle table name would break the query.
schema.CanonicalIdent— case/whitespace-normalized identifier for matchingcontent.orderedColumns— order columns by canonical name so both engines produce a comparable sequencecontent.hashRow— emit canonical column names so identical row data hashes equal regardless of casecontent.BuildDataDiff— match tables by canonical name; look up hashes by each side's real name; label output with the prod-side namerunDiff— build the shared-table set by canonical name so both sides get hashedScope / non-goals
integervsnumber,varcharvsvarchar2) remain visible — they are real differences, not masked.gen-pack/applySQL generation is unchanged. Generating a cross-engine migration pack to backfill the target is a separate, larger change (type mapping, quoting) and is intentionally out of scope here.Verification
End-to-end against live PostgreSQL 16 + Oracle XE 21 containers (Postgres = source of truth with 6 rows, Oracle = migrated target with 4 rows, one row's value changed):
Before →
No data differences found(count=0 tables matched)After →
{ "table": "customers", "removed_keys": ["5","6"], "updated_keys": ["4"] }i.e. ids 5 & 6 missing in Oracle, id 4 drifted — correct.
Tests
schema.TestCanonicalIdent(+ cross-engine match invariant)content.TestHashTable_CrossEngineCaseInsensitive— identical data hashes equal across identifier casecontent.TestBuildDataDiff_CaseInsensitiveTableMatch—customers↔CUSTOMERSmatches; missing/changed rows detectedAll existing content/schema tests continue to pass.
Summary by CodeRabbit