Skip to content

Conversation

ucpr
Copy link

@ucpr ucpr commented Jul 16, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Fix unstable tag generation for composite indexes with different column orders.

User Case Description

When multiple composite indexes exist on the same columns but in different orders, the generated code may have unstable tag output.

Example:

CREATE TABLE users (
    id INT PRIMARY KEY,
    email VARCHAR(255),
    name VARCHAR(255),

    -- composite indexes with different column orders
    INDEX idx_email_name (email, name),
    INDEX idx_name_email (name, email)
);

With a schema like the above, the generated tags can vary between runs:

// First run
Email string `gorm:"index:idx_email_name,priority:1;index:idx_name_email,priority:2"`

// Second run (order may differ)
Email string `gorm:"index:idx_name_email,priority:2;index:idx_email_name,priority:1"`

@ucpr ucpr marked this pull request as draft July 16, 2025 13:35
@ucpr ucpr marked this pull request as ready for review July 16, 2025 13:36
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