diff --git a/test.sh b/test.sh index 7acd3d07..3394761c 100755 --- a/test.sh +++ b/test.sh @@ -11,6 +11,14 @@ then verbose="-v" fi +function cleanup { + echo "Cleanup resources..." + docker-compose down + find ./sql_scripts/sqlite -name *.sqlite* -delete +} +# defer cleanup, so it will be executed even after premature exit +trap cleanup EXIT + docker-compose up -d sleep 10 # Ensure mysql is online @@ -30,7 +38,3 @@ test "postgres" test "cockroach" test "mysql" test "sqlite" - -docker-compose down - -find ./sql_scripts/sqlite -name *.sqlite* -delete \ No newline at end of file diff --git a/translators/mysql.go b/translators/mysql.go index b6454154..91b8f351 100644 --- a/translators/mysql.go +++ b/translators/mysql.go @@ -123,7 +123,7 @@ func (p *MySQL) RenameColumn(t fizz.Table) (string, error) { } } col := p.buildColumn(c) - col = strings.Replace(col, oc.Name, fmt.Sprintf("%s %s", oc.Name, nc.Name), -1) + col = strings.Replace(col, oc.Name, fmt.Sprintf("%s` `%s", oc.Name, nc.Name), -1) s := fmt.Sprintf("ALTER TABLE %s CHANGE %s;", p.escapeIdentifier(t.Name), col) return s, nil } diff --git a/translators/mysql_meta.go b/translators/mysql_meta.go index 24cc955a..7fad21ad 100644 --- a/translators/mysql_meta.go +++ b/translators/mysql_meta.go @@ -57,6 +57,7 @@ func (p *mysqlSchema) Version() (*semver.Version, error) { if err != nil { return version, errors.WithMessage(err, "could not fetch MySQL version") } + defer res.Close() for res.Next() { err = res.Scan(&version) @@ -77,6 +78,7 @@ func (p *mysqlSchema) Build() error { if err != nil { return err } + defer res.Close() for res.Next() { table := &fizz.Table{ Columns: []fizz.Column{}, diff --git a/translators/mysql_test.go b/translators/mysql_test.go index 99ce85e5..f47e07b1 100644 --- a/translators/mysql_test.go +++ b/translators/mysql_test.go @@ -15,7 +15,7 @@ var myt = translators.NewMySQL("", "") func init() { u := "%s:%s@(%s:%s)/%s?parseTime=true&multiStatements=true&readTimeout=1s&collation=%s" - u = fmt.Sprintf(u, envy.Get("MYSQL_USER", "root"), envy.Get("MYSQL_PASSWORD", ""), envy.Get("MYSQL_HOST", "127.0.0.1"), envy.Get("MYSQL_PORT", "3306"), "pop_test", "utf8_general_ci") + u = fmt.Sprintf(u, envy.Get("MYSQL_USER", "root"), envy.Get("MYSQL_PASSWORD", "root"), envy.Get("MYSQL_HOST", "127.0.0.1"), envy.Get("MYSQL_PORT", "3306"), "pop_test", "utf8_general_ci") myt = translators.NewMySQL(u, "pop_test") } @@ -280,7 +280,7 @@ func (p *MySQLSuite) Test_MySQL_RenameIndex() { ddl := `ALTER TABLE ` + "`users`" + ` RENAME INDEX ` + "`email_idx`" + ` TO ` + "`email_address_idx`" + `;` - res, err := fizz.AString(`rename_index("users", "email_idx", "email_address_ix")`, myt) + res, err := fizz.AString(`rename_index("users", "email_idx", "email_address_idx")`, myt) r.NoError(err) r.Equal(ddl, res) } diff --git a/translators/translators_test.go b/translators/translators_test.go index 6cfb9b9b..dcbb54e4 100644 --- a/translators/translators_test.go +++ b/translators/translators_test.go @@ -33,7 +33,7 @@ func TestSpecificSuites(t *testing.T) { suite.Run(t, &PostgreSQLSuite{}) case "cockroach": suite.Run(t, &CockroachSuite{}) - case "mysql": + case "mysql", "mysql_travis": suite.Run(t, &MySQLSuite{}) case "sqlite": suite.Run(t, &SQLiteSuite{})