Skip to content

Comments

fix: constraint multi-column ordering#22

Merged
tianzhou merged 2 commits intomainfrom
constraint_ordering
Sep 13, 2025
Merged

fix: constraint multi-column ordering#22
tianzhou merged 2 commits intomainfrom
constraint_ordering

Conversation

@tianzhou
Copy link
Contributor

This revives #17, which is reverted by #19

The addition is to change the testdata/diff/create_table/add_table_composite_keys test case so we can verify this issue before/after the fix.

Credit to @screenfluent for pushing this.

Copilot AI review requested due to automatic review settings September 13, 2025 08:55
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 an issue with multi-column constraint ordering by ensuring constraint columns are sorted by their database position. The change restores the correct column ordering for unique, primary key, and foreign key constraints that was previously broken.

  • Adds position-based sorting for constraint columns to preserve original database order
  • Updates test data to verify the fix with reordered UNIQUE constraint columns
  • Includes special handling to maintain existing partitioned table primary key logic

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/ir/inspector.go Adds position-based sorting logic for constraint columns and helper function
testdata/diff/create_table/add_table_composite_keys/plan.txt Updates expected output with reordered UNIQUE constraints for testing
testdata/diff/create_table/add_table_composite_keys/plan.sql Updates SQL test case with reordered UNIQUE constraints
testdata/diff/create_table/add_table_composite_keys/plan.json Updates JSON test case and version number
testdata/diff/create_table/add_table_composite_keys/new.sql Updates target schema with reordered UNIQUE constraints
testdata/diff/create_table/add_table_composite_keys/diff.sql Updates diff output with reordered UNIQUE constraints

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@tianzhou
Copy link
Contributor Author

cc @screenfluent

@tianzhou tianzhou merged commit 0312bdd into main Sep 13, 2025
2 checks passed
@tianzhou tianzhou deleted the constraint_ordering branch October 23, 2025 09:15
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.

1 participant