From c900ecc87fbd1e29a496a27d103adb07cfa9971f Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sat, 3 Sep 2022 10:12:17 +0800 Subject: [PATCH] Prevent Sync failure with non-regular indexes on Postgres (#2174) When dropping indexes in Postgres if the index is non-regular we should not attempt to regularise the index name as it is already correct. Signed-off-by: Andrew Thornton Reviewed-on: https://gitea.com/xorm/xorm/pulls/2174 Reviewed-by: Lunny Xiao Co-authored-by: Andrew Thornton Co-committed-by: Andrew Thornton --- dialects/postgres.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dialects/postgres.go b/dialects/postgres.go index 3c7ecb35..f9de5859 100644 --- a/dialects/postgres.go +++ b/dialects/postgres.go @@ -1030,11 +1030,10 @@ func (db *postgres) DropIndexSQL(tableName string, index *schemas.Index) string tableParts := strings.Split(strings.Replace(tableName, `"`, "", -1), ".") tableName = tableParts[len(tableParts)-1] - if !strings.HasPrefix(idxName, "UQE_") && - !strings.HasPrefix(idxName, "IDX_") { - if index.Type == schemas.UniqueType { + if index.IsRegular { + if index.Type == schemas.UniqueType && !strings.HasPrefix(idxName, "UQE_") { idxName = fmt.Sprintf("UQE_%v_%v", tableName, index.Name) - } else { + } else if index.Type == schemas.IndexType && !strings.HasPrefix(idxName, "IDX_") { idxName = fmt.Sprintf("IDX_%v_%v", tableName, index.Name) } }