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
@@ -19,6 +19,8 @@ const (
|
||||
sqliteResultBusy = 5
|
||||
sqliteResultLocked = 6
|
||||
sqlitePrimaryMask = 0xff
|
||||
sqliteUniqueKey = 2067
|
||||
sqlitePrimaryKey = 1555
|
||||
)
|
||||
|
||||
type sqliteDriver struct{}
|
||||
@@ -39,10 +41,20 @@ func (sqliteDriver) NewBackup(db *gorm.DB, directory string, now func() time.Tim
|
||||
}
|
||||
|
||||
func (sqliteDriver) IsLockContention(err error) bool {
|
||||
code, ok := sqliteCode(err)
|
||||
primary := code & sqlitePrimaryMask
|
||||
return ok && (primary == sqliteResultBusy || primary == sqliteResultLocked)
|
||||
}
|
||||
|
||||
func (sqliteDriver) IsUniqueViolation(err error) bool {
|
||||
code, ok := sqliteCode(err)
|
||||
return ok && (code == sqliteUniqueKey || code == sqlitePrimaryKey)
|
||||
}
|
||||
|
||||
func sqliteCode(err error) (int, bool) {
|
||||
var coded interface{ Code() int }
|
||||
if !errors.As(err, &coded) {
|
||||
return false
|
||||
return 0, false
|
||||
}
|
||||
primary := coded.Code() & sqlitePrimaryMask
|
||||
return primary == sqliteResultBusy || primary == sqliteResultLocked
|
||||
return coded.Code(), true
|
||||
}
|
||||
Reference in new issue
Block a user