Browse Source

feat: Refine account deletion script and rename

CassiopeiaCode 2 months ago
parent
commit
661cbe3105
1 changed files with 7 additions and 4 deletions
  1. 7 4
      scripts/delete_disabled_zero_success_accounts.py

+ 7 - 4
scripts/delete_disabled_zero_success_accounts.py

@@ -10,7 +10,7 @@ DB_PATH = BASE_DIR / "data.sqlite3"
 
 def delete_disabled_accounts() -> int:
     """
-    Delete all accounts where enabled=0 from the SQLite database.
+    Delete accounts where enabled=0 AND success_count=0 from the SQLite database.
     Returns the number of rows deleted.
     """
     if not DB_PATH.exists():
@@ -33,12 +33,15 @@ def delete_disabled_accounts() -> int:
             if "enabled" not in cols:
                 print("Column 'enabled' not found in 'accounts' table.")
                 return 0
+            if "success_count" not in cols:
+                print("Column 'success_count' not found in 'accounts' table.")
+                return 0
 
             # Count first for clear reporting, then delete
-            count = (conn.execute("SELECT COUNT(*) FROM accounts WHERE enabled=0").fetchone() or [0])[0]
-            conn.execute("DELETE FROM accounts WHERE enabled=0")
+            count = (conn.execute("SELECT COUNT(*) FROM accounts WHERE enabled=0 AND success_count=0").fetchone() or [0])[0]
+            conn.execute("DELETE FROM accounts WHERE enabled=0 AND success_count=0")
             conn.commit()
-            print(f"Deleted {count} disabled account(s).")
+            print(f"Deleted {count} disabled account(s) with zero success count.")
             return int(count)
     except sqlite3.Error as e:
         print(f"SQLite error: {e}", file=sys.stderr)