Set MySQL mode to ANSI on connection

This commit is contained in:
Denis Arh
2020-09-30 12:29:44 +02:00
parent f831a665eb
commit bccd90fde7
2 changed files with 5 additions and 3 deletions
+2
View File
@@ -49,6 +49,8 @@ func Connect(ctx context.Context, dsn string) (store.Storer, error) {
return nil, err
}
s.DB().ExecContext(ctx, "SET SESSION sql_mode = 'ANSI'")
return s, nil
}
+3 -3
View File
@@ -69,7 +69,7 @@ func (u upgrader) Before(ctx context.Context) error {
return err
}
if _, err := u.s.DB().ExecContext(ctx, fmt.Sprintf("DROP TABLE %s", migrations)); err != nil {
if _, err := u.s.DB().ExecContext(ctx, fmt.Sprintf(`DROP TABLE "%s"`, migrations)); err != nil {
return err
}
@@ -126,7 +126,7 @@ func (u upgrader) DropTable(ctx context.Context, table string) (dropped bool, er
return false, err
}
err = u.Exec(ctx, fmt.Sprintf(`DROP TABLE %s`, table))
err = u.Exec(ctx, fmt.Sprintf(`DROP TABLE "%s"`, table))
if err != nil {
return false, err
}
@@ -151,7 +151,7 @@ func (u upgrader) upgradeTable(ctx context.Context, t *ddl.Table) error {
func (u upgrader) TableExists(ctx context.Context, table string) (bool, error) {
var tmp interface{}
if err := u.s.DB().GetContext(ctx, &tmp, fmt.Sprintf("SHOW TABLES LIKE %q", table)); err == sql.ErrNoRows {
if err := u.s.DB().GetContext(ctx, &tmp, fmt.Sprintf(`SHOW TABLES LIKE '%s'`, table)); err == sql.ErrNoRows {
return false, nil
} else if err != nil {
return false, fmt.Errorf("could not check if table exists: %w", err)