Compitable with cockroach (#1930)

Fix #1292

Reviewed-on: https://gitea.com/xorm/xorm/pulls/1930
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Lunny Xiao 2021-06-09 14:07:34 +08:00
parent 7864cb5ae6
commit a6d2bfb4ba
1 changed files with 5 additions and 2 deletions

View File

@ -1221,7 +1221,8 @@ func (db *postgres) GetIndexes(queryer core.Queryer, ctx context.Context, tableN
continue
}
indexName = strings.Trim(indexName, `" `)
if strings.HasSuffix(indexName, "_pkey") {
// ignore primary index
if strings.HasSuffix(indexName, "_pkey") || strings.EqualFold(indexName, "primary") {
continue
}
if strings.HasPrefix(indexdef, "CREATE UNIQUE INDEX") {
@ -1241,7 +1242,9 @@ func (db *postgres) GetIndexes(queryer core.Queryer, ctx context.Context, tableN
index := &schemas.Index{Name: indexName, Type: indexType, Cols: make([]string, 0)}
for _, colName := range colNames {
index.Cols = append(index.Cols, strings.TrimSpace(strings.Replace(colName, `"`, "", -1)))
col := strings.TrimSpace(strings.Replace(colName, `"`, "", -1))
fields := strings.Split(col, " ")
index.Cols = append(index.Cols, fields[0])
}
index.IsRegular = isRegular
indexes[index.Name] = index