Skip to content

Commit 8da35cc

Browse files
committed
migrate fix
1 parent 637dd90 commit 8da35cc

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

orm/create_struct.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ func getTableDbColumns[T Table](query *Query[T]) ([]dBColumn, error) {
190190
cols := strings.Split(strings.Trim(keyNameAndCols[1], "()"), ",")
191191

192192
if len(cols) == 1 && cols[0] == keyNameAndCols[0] {
193-
keyName = "unique"
194-
} else if strings.HasPrefix(keyName, "unique_") == false {
195-
keyName = "unique_" + keyName
193+
keyName = uniqueKeyPrefix
194+
} else {
195+
keyName = uniqueKeyPrefix + "_" + keyName
196196
}
197197
for k2, v2 := range cols {
198198
colName := strings.Trim(v2, "`")
@@ -213,9 +213,9 @@ func getTableDbColumns[T Table](query *Query[T]) ([]dBColumn, error) {
213213
cols := strings.Split(strings.Trim(keyNameAndCols[1], "()"), ",")
214214

215215
if len(cols) == 1 && cols[0] == keyNameAndCols[0] {
216-
keyName = "index"
217-
} else if strings.HasPrefix(keyName, "index_") == false {
218-
keyName = "index_" + keyName
216+
keyName = keyPrefix
217+
} else {
218+
keyName = keyPrefix + "_" + keyName
219219
}
220220
for k2, v2 := range cols {
221221
colName := strings.Trim(v2, "`")

orm/create_table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ func getMigrateColumns(table *queryTable) []dBColumn {
312312
if v == uniqueKeyPrefix {
313313
column.Unique = true
314314
} else {
315-
column.Uniques = append(column.Uniques, v)
315+
column.Uniques = append(column.Uniques, strings.TrimPrefix(v, uniqueKeyPrefix+"_"))
316316
}
317317
} else if strings.HasPrefix(v, keyPrefix) {
318318
if v == keyPrefix {
319319
column.Index = true
320320
} else {
321-
column.Indexs = append(column.Indexs, v)
321+
column.Indexs = append(column.Indexs, strings.TrimPrefix(v, keyPrefix+"_"))
322322
}
323323
} else {
324324
overideColumn.Type = v

0 commit comments

Comments
 (0)