fix(migrator): support functional prefix indexes for PostgreSQL#7753
fix(migrator): support functional prefix indexes for PostgreSQL#7753hamid17amu wants to merge 2 commits intogo-gorm:masterfrom
Conversation
|
Fix This PR updates index SQL generation in The change appears to be a targeted bug fix for invalid PostgreSQL index SQL generation from Key Changes• Modified Affected Areas• This summary was automatically generated by @propel-code-bot |
Co-authored-by: propel-code-bot[bot] <203372662+propel-code-bot[bot]@users.noreply.github.com>
|
@jinzhu Please review |
What did this pull request do?
1. The Problem
GORM currently uses MySQL-specific syntax
column(length)when generating indexes with alengthtag. While this works for MySQL, it is invalid in PostgreSQL. Currently, when a user definesgorm:"index:idx_name,length:10"in a Postgres environment, GORM generates:CREATE INDEX "idx_name" ON "table" ("column"(10))This results in either a syntax error or a standard B-tree index that ignores the length, depending on the driver version.
2. The Solution
This PR introduces two changes:
Schema Parser: Updates
parseFieldIndexesto be case-insensitive when looking for thelengthtag, ensuringlength:10andLENGTH:10both populate theIndexOption.Lengthfield.Migrator: Updates
BuildIndexOptionsto check the database dialect. If the dialect is PostgreSQL, it uses the functional LEFT(column, length) syntax wrapped in parentheses.3. Impact
User Case Description
AutoMigrateon a PostgreSQL database.\d users.idx_name btree (left(name, 10))Resolves #7752