mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
dialect/sql/mysql: fix verifyrange check for mysql (#337)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user