Skip to content

Conversation

@tianzhou
Copy link
Contributor

Fix #195

Copilot AI review requested due to automatic review settings December 18, 2025 06:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #195 by implementing topological sorting for PostgreSQL type creation to ensure types are created in the correct dependency order. Previously, types were sorted alphabetically (with domains last), which could fail when composite types reference other custom types like enums.

Key changes:

  • Replaced simple alphabetical sorting with dependency-aware topological sorting using Kahn's algorithm
  • Added support for detecting type-to-type dependencies in composite types and domain types
  • Added test case demonstrating correct ordering of enum and composite types with dependencies

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/diff/type.go Replaced alphabetical sorting logic with call to new topologicallySortTypes function
internal/diff/topological.go Added topologicallySortTypes, extractTypeName, and findLastDot functions to implement dependency-aware type sorting
testdata/diff/dependency/type_to_type/new.sql Test input with composite type referencing enum type
testdata/diff/dependency/type_to_type/old.sql Empty schema baseline for test
testdata/diff/dependency/type_to_type/plan.sql Expected SQL output with correct type ordering (enum before composite)
testdata/diff/dependency/type_to_type/plan.txt Human-readable plan showing the expected migration steps
testdata/diff/dependency/type_to_type/plan.json JSON format of the migration plan
testdata/diff/dependency/type_to_type/diff.sql Generated diff SQL matching expected plan

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI commented Dec 18, 2025

@tianzhou I've opened a new pull request, #206, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 18, 2025

@tianzhou I've opened a new pull request, #207, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits December 17, 2025 22:54
* Initial plan

* Add detailed cycle-breaking comments to topologicallySortTypes

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

* Fix line reference in topologicallySortTypes comment

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>
* Initial plan

* Add comprehensive unit tests for topologicallySortTypes function

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

* Remove duplicate newTestCompositeTypeMultiple helper function

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tianzhou tianzhou merged commit 6fae200 into main Dec 18, 2025
8 checks passed
@tianzhou tianzhou deleted the dependency branch December 18, 2025 07:24
alecthomas pushed a commit to alecthomas/pgschema that referenced this pull request Jan 26, 2026
* fix: type topological sort

* Add detailed cycle-breaking comments to topologicallySortTypes (pgplex#206)

* Initial plan

* Add detailed cycle-breaking comments to topologicallySortTypes

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

* Fix line reference in topologicallySortTypes comment

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

* Add unit tests for topologicallySortTypes function (pgplex#207)

* Initial plan

* Add comprehensive unit tests for topologicallySortTypes function

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

* Remove duplicate newTestCompositeTypeMultiple helper function

Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tianzhou <230323+tianzhou@users.noreply.github.com>

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
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.

Interdependent types do not get dumped in the correct order in some cases

2 participants