From ded5c5ef7df2ef85a909356d5bac5a383c43a151 Mon Sep 17 00:00:00 2001 From: Nurahmadie Date: Thu, 27 Mar 2014 17:43:07 +0700 Subject: [PATCH] sync mysql behavior with sqlite --- pkg/database/migrate/mysql.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/database/migrate/mysql.go b/pkg/database/migrate/mysql.go index 248b510c..7fe29ce6 100644 --- a/pkg/database/migrate/mysql.go +++ b/pkg/database/migrate/mysql.go @@ -21,7 +21,8 @@ func MySQL(tx *sql.Tx) *MigrationDriver { } func (m *mysqlDriver) CreateTable(tableName string, args []string) (sql.Result, error) { - return m.Tx.Exec(fmt.Sprintf("CREATE TABLE %s (%s) ROW_FORMAT=DYNAMIC", tableName, strings.Join(args, ", "))) + return m.Tx.Exec(fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (%s) ROW_FORMAT=DYNAMIC", + tableName, strings.Join(args, ", "))) } func (m *mysqlDriver) RenameTable(tableName, newName string) (sql.Result, error) { @@ -41,6 +42,9 @@ func (m *mysqlDriver) ChangeColumn(tableName, columnName, newSpecs string) (sql. } func (m *mysqlDriver) DropColumns(tableName string, columnsToDrop ...string) (sql.Result, error) { + if len(columnsToDrop) == 0 { + return nil, fmt.Errorf("No columns to drop.") + } for k, v := range columnsToDrop { columnsToDrop[k] = fmt.Sprintf("DROP %s", v) }