1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 18:30:56 +00:00

Merge pull request #3017 from Medicean/develop

Update: Fix migration generate SQL
This commit is contained in:
astaxie 2018-01-05 00:10:16 +08:00 committed by GitHub
commit e81f1e53bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -322,7 +322,7 @@ func (m *Migration) GetSQL() (sql string) {
sql += fmt.Sprintf("\n DROP COLUMN `%s`", column.Name) sql += fmt.Sprintf("\n DROP COLUMN `%s`", column.Name)
} }
if len(m.Columns) > index { if len(m.Columns) > index+1 {
sql += "," sql += ","
} }
} }
@ -355,7 +355,7 @@ func (m *Migration) GetSQL() (sql string) {
} else { } else {
sql += fmt.Sprintf("\n DROP COLUMN `%s`", column.Name) sql += fmt.Sprintf("\n DROP COLUMN `%s`", column.Name)
} }
if len(m.Columns) > index { if len(m.Columns) > index+1 {
sql += "," sql += ","
} }
} }
@ -366,14 +366,14 @@ func (m *Migration) GetSQL() (sql string) {
for index, unique := range m.Uniques { for index, unique := range m.Uniques {
sql += fmt.Sprintf("\n DROP KEY `%s`", unique.Definition) sql += fmt.Sprintf("\n DROP KEY `%s`", unique.Definition)
if len(m.Uniques) > index { if len(m.Uniques) > index+1 {
sql += "," sql += ","
} }
} }
for index, column := range m.Renames { for index, column := range m.Renames {
sql += fmt.Sprintf("\n CHANGE COLUMN `%s` `%s` %s %s %s %s", column.NewName, column.OldName, column.OldDataType, column.OldUnsign, column.OldNull, column.OldDefault) sql += fmt.Sprintf("\n CHANGE COLUMN `%s` `%s` %s %s %s %s", column.NewName, column.OldName, column.OldDataType, column.OldUnsign, column.OldNull, column.OldDefault)
if len(m.Renames) > index { if len(m.Renames) > index+1 {
sql += "," sql += ","
} }
} }