Skip to content

Commit

Permalink
Use DELETE FROM instead of TRUNCATE for MySQL (#656)
Browse files Browse the repository at this point in the history
* Use DELETE FROM instead of TRUNCATE for MySQL

* Set isolation level to SERIALIZABLE

Co-authored-by: Martin Arrieta <mail@martinarrieta.me>
  • Loading branch information
antigremlin and martinarrieta committed Dec 18, 2021
1 parent 918e13a commit 9f5ed82
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions database/mysql/mysql.go
Expand Up @@ -336,12 +336,12 @@ func (m *Mysql) Run(migration io.Reader) error {
}

func (m *Mysql) SetVersion(version int, dirty bool) error {
tx, err := m.conn.BeginTx(context.Background(), &sql.TxOptions{})
tx, err := m.conn.BeginTx(context.Background(), &sql.TxOptions{Isolation: sql.LevelSerializable})
if err != nil {
return &database.Error{OrigErr: err, Err: "transaction start failed"}
}

query := "TRUNCATE `" + m.config.MigrationsTable + "`"
query := "DELETE FROM `" + m.config.MigrationsTable + "`"
if _, err := tx.ExecContext(context.Background(), query); err != nil {
if errRollback := tx.Rollback(); errRollback != nil {
err = multierror.Append(err, errRollback)
Expand Down

0 comments on commit 9f5ed82

Please sign in to comment.