smal nits

This commit is contained in:
6543 2020-06-27 23:31:15 +02:00
parent 55afb620e8
commit 0f8d350393
No known key found for this signature in database
GPG Key ID: A1CA74D27FD13271
2 changed files with 5 additions and 2 deletions

View File

@ -340,8 +340,8 @@ func TestDropTableCols(t *testing.T) {
} }
assert.NoError(t, PrepareEngine()) assert.NoError(t, PrepareEngine())
assertSync(t, new(TestDropTableCols))
assert.NoError(t, testEngine.Sync2(new(TestDropTableCols)))
schema, err := testEngine.TableInfo(new(TestDropTableCols)) schema, err := testEngine.TableInfo(new(TestDropTableCols))
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, schema.GetColumn("to_drop")) assert.NotNil(t, schema.GetColumn("to_drop"))

View File

@ -216,6 +216,7 @@ func (session *Session) dropTableCols(beanOrTableName interface{}, cols []string
if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `new_%s_new` RENAME TO `%s`", tableName, tableName)); err != nil { if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `new_%s_new` RENAME TO `%s`", tableName, tableName)); err != nil {
return err return err
} }
case schemas.POSTGRES: case schemas.POSTGRES:
columns := "" columns := ""
for _, col := range cols { for _, col := range cols {
@ -227,6 +228,7 @@ func (session *Session) dropTableCols(beanOrTableName interface{}, cols []string
if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, columns)); err != nil { if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, columns)); err != nil {
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err) return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err)
} }
case schemas.MYSQL: case schemas.MYSQL:
// Drop indexes on columns first // Drop indexes on columns first
sql := fmt.Sprintf("SHOW INDEX FROM %s WHERE column_name IN ('%s')", tableName, strings.Join(cols, "','")) sql := fmt.Sprintf("SHOW INDEX FROM %s WHERE column_name IN ('%s')", tableName, strings.Join(cols, "','"))
@ -255,6 +257,7 @@ func (session *Session) dropTableCols(beanOrTableName interface{}, cols []string
if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, columns)); err != nil { if _, err := session.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, columns)); err != nil {
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err) return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err)
} }
case schemas.MSSQL: case schemas.MSSQL:
columns := "" columns := ""
for _, col := range cols { for _, col := range cols {
@ -281,9 +284,9 @@ func (session *Session) dropTableCols(beanOrTableName interface{}, cols []string
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err) return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err)
} }
return session.Commit()
case schemas.ORACLE: case schemas.ORACLE:
return fmt.Errorf("not implemented for oracle") return fmt.Errorf("not implemented for oracle")
default: default:
return fmt.Errorf("unrecognized DB") return fmt.Errorf("unrecognized DB")
} }