fix: preserve dependency order for views in multi-file dump (#307)#310
fix: preserve dependency order for views in multi-file dump (#307)#310
Conversation
The multi-file dump mode was sorting view includes alphabetically, which broke dependency ordering when a view depended on another view that sorted later in the alphabet. Now preserves the topological ordering from the diff package instead of re-sorting alphabetically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryFixed a critical bug in multi-file dump mode where view include directives were sorted alphabetically, breaking dependency ordering when a view depended on another view that sorted later alphabetically. Key Changes:
Testing:
Confidence Score: 5/5
Important Files Changed
Last reviewed commit: bfe4d53 |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where views in multi-file dump mode were being sorted alphabetically instead of preserving the dependency order established by the diff package's topological sort. This caused SQL execution failures when a view depended on another view with an alphabetically later name (e.g., dashboard depending on item_summary).
Changes:
- Modified multi-file formatter to preserve topological ordering by tracking insertion order instead of re-sorting alphabetically
- Added comprehensive test coverage for both single-file and multi-file view dependency ordering
- Removed unnecessary sort.Strings import from formatter.go
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/dump/formatter.go | Replaced alphabetical sorting with insertion-order tracking via orderByDir map to preserve topological dependency ordering from diff package |
| cmd/dump/dump_integration_test.go | Added two integration tests: one for single-file mode (using existing test harness) and one for multi-file mode (explicitly verifying include directive order) |
| testdata/dump/issue_307_view_dependency_order/raw.sql | Test schema demonstrating the issue: dashboard view depends on item_summary view |
| testdata/dump/issue_307_view_dependency_order/pgschema.sql | Expected output showing correct ordering: item_summary before dashboard |
| testdata/dump/issue_307_view_dependency_order/pgdump.sql | pg_dump reference output for comparison |
| testdata/dump/issue_307_view_dependency_order/manifest.json | Test metadata describing the test case |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
pgschema dump --multi-filemode was sorting view include directives alphabetically, breaking dependency ordering when a view depended on another view that sorted later in the alphabet (e.g.,dashboarddepends onitem_summary, butdashboard.sqlwas included beforeitem_summary.sql)Fixes #307
Test plan
TestDumpCommand_Issue307ViewDependencyOrder- verifies single-file dump outputs views in dependency orderTestDumpCommand_Issue307MultiFileViewDependencyOrder- verifies multi-file dump include directives are in dependency order (item_summary before dashboard)🤖 Generated with Claude Code