mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-05-31 10:14:15 +00:00
fix(inbounds): reset id sequence on delete so old ids are reused
SQLite AUTOINCREMENT keeps a high-water mark in sqlite_sequence that deleting rows never lowers, so after removing inbounds the next add kept climbing instead of reusing freed ids. DelInbound now realigns the counter to MAX(id) after each delete, clearing the sqlite_sequence row entirely when the table is empty so the next inbound starts at id 1. Guarded behind !IsPostgres(); Postgres sequences are left untouched.
This commit is contained in:
parent
cf50952921
commit
80110f9404
1 changed files with 17 additions and 1 deletions
|
|
@ -614,7 +614,23 @@ func (s *InboundService) DelInbound(id int) (bool, error) {
|
|||
return false, err
|
||||
}
|
||||
|
||||
return needRestart, db.Delete(model.Inbound{}, id).Error
|
||||
if err := db.Delete(model.Inbound{}, id).Error; err != nil {
|
||||
return needRestart, err
|
||||
}
|
||||
if !database.IsPostgres() {
|
||||
var maxId int
|
||||
if err := db.Model(&model.Inbound{}).Select("COALESCE(MAX(id), 0)").Scan(&maxId).Error; err != nil {
|
||||
return needRestart, err
|
||||
}
|
||||
if maxId == 0 {
|
||||
if err := db.Exec("DELETE FROM sqlite_sequence WHERE name = ?", "inbounds").Error; err != nil {
|
||||
return needRestart, err
|
||||
}
|
||||
} else if err := db.Exec("UPDATE sqlite_sequence SET seq = ? WHERE name = ?", maxId, "inbounds").Error; err != nil {
|
||||
return needRestart, err
|
||||
}
|
||||
}
|
||||
return needRestart, nil
|
||||
}
|
||||
|
||||
type BulkDelInboundResult struct {
|
||||
|
|
|
|||
Loading…
Reference in a new issue