修复 mysql 语句生成的BUG
This commit is contained in:
parent
572ed2b0f3
commit
5c7a0d235e
@ -88,15 +88,15 @@ func (i *Index) ToString(tableName string) (string, error) {
|
|||||||
// 拼接sql
|
// 拼接sql
|
||||||
switch i.Type {
|
switch i.Type {
|
||||||
case TableIndexPrimary:
|
case TableIndexPrimary:
|
||||||
return fmt.Sprintf("ALTER TABLE `%v` ADD PRIMARY KEY (%v)", tableName, i.FieldList[0]), nil
|
return fmt.Sprintf("PRIMARY KEY (%v)", i.FieldList[0]), nil
|
||||||
case TableIndexUnique:
|
case TableIndexUnique:
|
||||||
return fmt.Sprintf("ALTER TABLE `%v` ADD UNIQUE KEY %v (%v)", tableName, i.Name, strings.Join(i.FieldList, ",")), nil
|
return fmt.Sprintf("UNIQUE KEY %v (%v)", i.Name, strings.Join(i.FieldList, ",")), nil
|
||||||
case TableIndexKey:
|
case TableIndexKey:
|
||||||
return fmt.Sprintf("ALTER TABLE `%v` ADD KEY %v (%v)", tableName, i.Name, strings.Join(i.FieldList, ",")), nil
|
return fmt.Sprintf("KEY %v (%v)", i.Name, strings.Join(i.FieldList, ",")), nil
|
||||||
case TableIndexIndex:
|
case TableIndexIndex:
|
||||||
return fmt.Sprintf("ALTER TABLE `%v` ADD INDEX %v (%v)", tableName, i.Name, strings.Join(i.FieldList, ",")), nil
|
return fmt.Sprintf("INDEX %v (%v)", i.Name, strings.Join(i.FieldList, ",")), nil
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf("ALTER TABLE `%v` ADD %v %v (%v)", tableName, i.Type, i.Name, strings.Join(i.FieldList, ",")), nil
|
return fmt.Sprintf("%v %v (%v)", i.Type, i.Name, strings.Join(i.FieldList, ",")), nil
|
||||||
}
|
}
|
||||||
case consts.DatabaseDriverSqlite3:
|
case consts.DatabaseDriverSqlite3:
|
||||||
// 拼接sql
|
// 拼接sql
|
||||||
|
@ -127,7 +127,10 @@ func (t *Table) ToString() ([]string, error) {
|
|||||||
indexList = append(indexList, indexStr)
|
indexList = append(indexList, indexStr)
|
||||||
}
|
}
|
||||||
replaceTable[TableFieldList] = strings.Join(fieldList, ",")
|
replaceTable[TableFieldList] = strings.Join(fieldList, ",")
|
||||||
replaceTable[TableIndexList] = strings.Join(indexList, ",")
|
if len(indexList) > 0 && consts.DatabaseDriverMysql == DatabaseDriver {
|
||||||
|
replaceTable[TableIndexList] = "," + strings.Join(indexList, ",")
|
||||||
|
indexList = make([]string, 0)
|
||||||
|
}
|
||||||
|
|
||||||
if len(t.Engine) > 0 {
|
if len(t.Engine) > 0 {
|
||||||
replaceTable[TableEngine] = "ENGINE=" + t.Engine
|
replaceTable[TableEngine] = "ENGINE=" + t.Engine
|
||||||
|
Loading…
Reference in New Issue
Block a user