diff --git a/integrations/session_schema_test.go b/integrations/session_schema_test.go index 47eef961..74e067c1 100644 --- a/integrations/session_schema_test.go +++ b/integrations/session_schema_test.go @@ -340,8 +340,8 @@ func TestDropTableCols(t *testing.T) { } assert.NoError(t, PrepareEngine()) + assertSync(t, new(TestDropTableCols)) - assert.NoError(t, testEngine.Sync2(new(TestDropTableCols))) schema, err := testEngine.TableInfo(new(TestDropTableCols)) assert.NoError(t, err) assert.NotNil(t, schema.GetColumn("to_drop")) diff --git a/session_schema.go b/session_schema.go index 6b55a18c..93a7416b 100644 --- a/session_schema.go +++ b/session_schema.go @@ -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 { return err } + case schemas.POSTGRES: columns := "" 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 { return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err) } + case schemas.MYSQL: // Drop indexes on columns first 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 { return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, cols, err) } + case schemas.MSSQL: columns := "" 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 session.Commit() case schemas.ORACLE: return fmt.Errorf("not implemented for oracle") + default: return fmt.Errorf("unrecognized DB") }