Преглед на файлове

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.
MHSanaei преди 6 часа
родител
ревизия
80110f9404
променени са 1 файла, в които са добавени 17 реда и са изтрити 1 реда
  1. 17 1
      web/service/inbound.go

+ 17 - 1
web/service/inbound.go

@@ -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 {