fix: ensure deterministic index order in generated models#1410
Open
tomoropy wants to merge 1 commit intogo-gorm:masterfrom
Open
fix: ensure deterministic index order in generated models#1410tomoropy wants to merge 1 commit intogo-gorm:masterfrom
tomoropy wants to merge 1 commit intogo-gorm:masterfrom
Conversation
Sort indexes by name before generating GORM tags to ensure consistent output across multiple code generation runs. This fixes the issue where index order in generated models was non-deterministic, causing CI diffs on each generation. Fixes: #<issue番号>
|
Deterministic index ordering in generated GORM model tags The PR adds alphabetical sorting for index definitions when building GORM tags, eliminating non-deterministic ordering that previously caused spurious diffs during repeated code-generation runs. Only one file is modified with a small, non-breaking change. Key Changes• Imported Affected Areas• This summary was automatically generated by @propel-code-bot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sort indexes by name before generating GORM tags to ensure consistent output across multiple code generation runs.
This fixes the issue where index order in generated models was non-deterministic, causing CI diffs on each generation.
Fixes: #1409
What did this pull request do?
This PR fixes the non-deterministic index order issue in generated GORM models. Previously, when generating models with multiple indexes on the same column, the order of indexes in the GORM tag could vary between generation runs, causing unnecessary diffs in CI/CD pipelines.
Changes:
buildGormTag()method ininternal/model/tbl_column.gosortpackage to enable index sortingExample:
Before this fix, a column with indexes
idx_payout_tenant_payment_atandidx_payout_tenant_idcould generate tags in different orders:index:idx_payout_tenant_id,priority:1;index:idx_payout_tenant_payment_at,priority:2index:idx_payout_tenant_payment_at,priority:2;index:idx_payout_tenant_id,priority:1After this fix, the order is always deterministic (alphabetical):
index:idx_payout_tenant_id,priority:1;index:idx_payout_tenant_payment_at,priority:2User Case Description
Problem:
When using GORM gen to generate models, the index order in generated GORM tags was non-deterministic. This caused CI/CD pipelines to fail with false-positive diffs on every code generation run, even when the actual database schema hadn't changed.
Use Case:
gento generate models from database schemaSolution:
By sorting indexes alphabetically by name before generating tags, the output is now deterministic and consistent across all generation runs, eliminating false-positive CI diffs.