dialect/sql/mysql: fix verifyrange check for mysql (#337)

This commit is contained in:
Ariel Mashraki
2020-02-09 16:09:02 +02:00
committed by GitHub
parent 9f9596c184
commit ab71992b7c
2 changed files with 2 additions and 2 deletions

View File

@@ -136,7 +136,7 @@ func (d *MySQL) verifyRange(ctx context.Context, tx dialect.Tx, t *Table, expect
// Table is empty and auto-increment is not configured. This can happen
// because MySQL (< 8.0) stores the auto-increment counter in main memory
// (not persistent), and the value is reset on restart (if table is empty).
if actual.Int64 == 0 {
if actual.Int64 <= 1 {
return d.setRange(ctx, tx, t, expected)
}
return nil

View File

@@ -1087,7 +1087,7 @@ func TestMySQL_Create(t *testing.T) {
mock.ExpectQuery(escape("SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `TABLE_NAME` = ?")).
WithArgs("users").
WillReturnRows(sqlmock.NewRows([]string{"AUTO_INCREMENT"}).
AddRow(0))
AddRow(1))
// restore the auto-increment counter.
mock.ExpectExec(escape("ALTER TABLE `users` AUTO_INCREMENT = 4294967296")).
WillReturnResult(sqlmock.NewResult(0, 1))