Skip to content

Schema Diff: reinstate dependency ordering of the generated script - #10319

Open
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/10295-dependency-ordering
Open

Schema Diff: reinstate dependency ordering of the generated script#10319
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/10295-dependency-ordering

Conversation

@dpage

@dpage dpage commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What this is

dependLevel drives the order in which generateFinalScript() writes objects into the generated script, with higher levels emitted first so dependencies land before whatever needs them. Nothing has assigned it since the React port deleted schema_diff_dependency.js wholesale: every row got Object.keys' default undefined bucket, so the script came out in whatever order the rows happened to be in. In practice this means a generated script can fail outright when an object appears before something it depends on.

The fix

computeDependLevels() rebuilds the levels for the full result set from each row's dependencies, walking the reverse graph so that a row which other rows depend on always ends up with the highest of their levels plus one, with a cycle guard for the circular dependencies the script header already warns about. It's called once, over the full row set, before the script is assembled.

Testing

Added Jest unit tests for computeDependLevels() covering a dependency chain, unrelated rows, a circular dependency, a dependency pointing at an object outside the row set, and converging dependency chains of different depths. Existing schema_diff Jest specs and eslint both pass clean.

Fixes #10295.

Summary by CodeRabbit

  • Bug Fixes
    • Improved schema diff script generation by ordering statements according to object dependencies.
    • Added handling for circular dependencies, missing dependency targets, unrelated objects, and converging dependency chains.
  • Tests
    • Added coverage for dependency ordering and edge cases to help ensure reliable script generation.

dependLevel drove the order in which generateFinalScript() writes
objects, with higher levels emitted first so dependencies land before
whatever needs them, but nothing has assigned it since the React port
deleted schema_diff_dependency.js: every row got Object.keys' default
undefined bucket, so the script came out in whatever order the rows
happened to be in.

computeDependLevels() rebuilds the levels for the full result set from
each row's dependencies, walking the reverse graph so a row that other
rows depend on always ends up with the highest of their levels plus
one, with a cycle guard for the circular dependencies the script header
already warns about.

Fixes pgadmin-org#10295.
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 50e34494-b8bd-43ef-8374-a36b2fad1793

📥 Commits

Reviewing files that changed from the base of the PR and between 0ebefaf and 944b60c.

📒 Files selected for processing (2)
  • web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffCompare.jsx
  • web/regression/javascript/schema_diff/schema_diff_compare_spec.js

Included review availability: Your plan provides up to 8 included reviews per hour; 0 remain after this review.


Walkthrough

Schema Diff now computes dependency levels for compared objects before generating a script. The calculation handles dependency chains, unrelated objects, missing targets, and circular dependencies. Regression tests cover these cases and verify deepest-chain selection.

Changes

Schema Diff dependency ordering

Layer / File(s) Summary
Dependency level calculation and validation
web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffCompare.jsx, web/regression/javascript/schema_diff/schema_diff_compare_spec.js
computeDependLevels builds reverse dependency relationships, assigns levels recursively, handles missing OIDs and circular dependencies, and has regression coverage for dependency ordering cases.
Script generation wiring
web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffCompare.jsx
Script generation computes dependency levels before grouping selected DDL statements.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 944b6

This change restores dependency-based ordering for generated scripts and includes focused tests; no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states that dependency ordering is restored for generated Schema Diff scripts.
Linked Issues check ✅ Passed The changes restore dependency-level calculation before script generation and add tests for the linked issue requirements [#10295].
Out of Scope Changes check ✅ Passed All changes directly support dependency ordering and its regression coverage for Schema Diff scripts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Schema Diff: generated script is no longer ordered by dependency (dependLevel is never set since the React port)

1 participant