refac: migration crash, real-database tests, site deleted during create, ruels out of the repo, lists
This commit is contained in:
1 parent
680b9a1308
commit
9d284e65a9
62 files changed
+1858
-987
No files matched your search
@@ -28,6 +28,8 @@ const (
|
||||
mysqlLockWaitTimeout = 1205
|
||||
mysqlDeadlock = 1213
|
||||
mysqlSnapshotChanged = 1020
|
||||
mysqlDuplicateEntry = 1062
|
||||
mysqlDuplicateKeyed = 1586
|
||||
)
|
||||
|
||||
type mysqlDriver struct{}
|
||||
@@ -94,6 +96,16 @@ func tableOptionsFor(db *gorm.DB) *gorm.DB {
|
||||
var mysqlContentionCodes = []uint16{mysqlLockNowait, mysqlLockWaitTimeout, mysqlDeadlock, mysqlSnapshotChanged}
|
||||
|
||||
func (mysqlDriver) IsLockContention(err error) bool {
|
||||
return hasMySQLCode(err, mysqlContentionCodes)
|
||||
}
|
||||
|
||||
var mysqlUniqueViolationCodes = []uint16{mysqlDuplicateEntry, mysqlDuplicateKeyed}
|
||||
|
||||
func (mysqlDriver) IsUniqueViolation(err error) bool {
|
||||
return hasMySQLCode(err, mysqlUniqueViolationCodes)
|
||||
}
|
||||
|
||||
func hasMySQLCode(err error, codes []uint16) bool {
|
||||
var failure *mysqldriver.MySQLError
|
||||
return errors.As(err, &failure) && slices.Contains(mysqlContentionCodes, failure.Number)
|
||||
return errors.As(err, &failure) && slices.Contains(codes, failure.Number)
|
||||
}
|
||||
Reference in new issue
Block a user