Fix bot binding and terminal device limits

This commit is contained in:
ShukeBta
2026-06-17 01:06:20 +08:00
parent 8e5bf73edc
commit 3368ac2947
10 changed files with 142 additions and 56 deletions
+1 -1
View File
@@ -798,7 +798,7 @@ WHERE deleted_at IS NULL
SELECT id
FROM (
SELECT id,
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at ASC, id ASC) AS rn
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY updated_at DESC, created_at DESC, id DESC) AS rn
FROM telegram_bindings
WHERE deleted_at IS NULL
) AS ranked_bindings
+7
View File
@@ -43,6 +43,13 @@ func TestEnforceTelegramBindingOneToOneCleansDuplicatesAndAddsIndex(t *testing.T
if count != 1 {
t.Fatalf("active bindings for user-1 = %d, want 1", count)
}
var kept model.TelegramBinding
if err := db.First(&kept, "user_id = ?", "user-1").Error; err != nil {
t.Fatal(err)
}
if kept.TelegramUserID != 10002 {
t.Fatalf("kept telegram binding = %d, want newest 10002", kept.TelegramUserID)
}
if err := db.Create(&model.TelegramBinding{TelegramUserID: 10003, ChatID: 10003, UserID: "user-1"}).Error; err == nil {
t.Fatal("expected unique index to reject another active binding for the same user")
}