Cleanup Scripts: - cleanup_graph.py - Clean up duplicate entities and orphaned nodes - cleanup_wiki.py - Remove orphaned pages and fix broken links - Utility scripts for database maintenance - Not part of main application, run manually
127 lines
3.3 KiB
Python
Executable File
127 lines
3.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Cleanup script to delete all wiki pages via REST API.
|
|
This will trigger automatic vector and graph cleanup for each page.
|
|
"""
|
|
import requests
|
|
import time
|
|
import sys
|
|
|
|
# Configuration
|
|
BASE_URL = "http://192.168.86.149:8089"
|
|
API_KEY = "af88ed8f44bed81bdb20d0534f1c4547340b29e2aba4963f61a71b993d7eb6e5"
|
|
USER = "jpmschweitzer"
|
|
|
|
headers = {
|
|
"Authorization": f"Bearer {API_KEY}",
|
|
"Content-Type": "application/json"
|
|
}
|
|
|
|
def list_all_pages():
|
|
"""List all wiki pages."""
|
|
url = f"{BASE_URL}/wiki/pages"
|
|
params = {"user": USER, "limit": 200}
|
|
|
|
print(f"🔍 Listing all pages for user: {USER}")
|
|
response = requests.get(url, headers=headers, params=params)
|
|
|
|
if response.status_code != 200:
|
|
print(f"❌ Failed to list pages: {response.status_code}")
|
|
print(response.text)
|
|
return []
|
|
|
|
data = response.json()
|
|
pages = data.get("pages", [])
|
|
print(f"📚 Found {len(pages)} pages")
|
|
return pages
|
|
|
|
def delete_page(page_id, title):
|
|
"""Delete a single wiki page."""
|
|
url = f"{BASE_URL}/wiki/pages/{page_id}"
|
|
params = {"user": USER}
|
|
|
|
print(f"🗑️ Deleting page {page_id}: {title}")
|
|
response = requests.delete(url, headers=headers, params=params)
|
|
|
|
if response.status_code == 200:
|
|
print(f" ✅ Deleted successfully")
|
|
return True
|
|
else:
|
|
print(f" ❌ Failed: {response.status_code}")
|
|
print(f" {response.text}")
|
|
return False
|
|
|
|
def main():
|
|
print("=" * 60)
|
|
print("🧹 Wiki Cleanup Script")
|
|
print("=" * 60)
|
|
print()
|
|
|
|
# List all pages
|
|
pages = list_all_pages()
|
|
|
|
if not pages:
|
|
print("✨ No pages found. Wiki is already clean!")
|
|
return
|
|
|
|
print()
|
|
print(f"⚠️ WARNING: About to delete {len(pages)} pages!")
|
|
print(" This will also delete:")
|
|
print(" - Vector embeddings in Qdrant")
|
|
print(" - Document nodes in Neo4j")
|
|
print()
|
|
|
|
# Ask for confirmation
|
|
response = input("Continue? (yes/no): ").strip().lower()
|
|
if response != "yes":
|
|
print("❌ Cancelled")
|
|
return
|
|
|
|
print()
|
|
print("🚀 Starting deletion...")
|
|
print()
|
|
|
|
# Delete each page
|
|
success_count = 0
|
|
failed_count = 0
|
|
|
|
for i, page in enumerate(pages, 1):
|
|
page_id = page.get("id")
|
|
title = page.get("title", "Untitled")
|
|
|
|
print(f"[{i}/{len(pages)}] ", end="")
|
|
|
|
if delete_page(page_id, title):
|
|
success_count += 1
|
|
else:
|
|
failed_count += 1
|
|
|
|
# Small delay to avoid overwhelming the API
|
|
time.sleep(0.2)
|
|
|
|
print()
|
|
print("=" * 60)
|
|
print("📊 Cleanup Summary")
|
|
print("=" * 60)
|
|
print(f"✅ Successfully deleted: {success_count} pages")
|
|
print(f"❌ Failed to delete: {failed_count} pages")
|
|
print(f"📝 Total pages: {len(pages)}")
|
|
print()
|
|
|
|
if success_count > 0:
|
|
print("🧹 Background cleanup tasks are running to remove:")
|
|
print(" - Vector embeddings from Qdrant")
|
|
print(" - Document nodes from Neo4j")
|
|
print()
|
|
print("✨ Wiki cleanup complete!")
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
print("\n\n❌ Interrupted by user")
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
print(f"\n\n❌ Error: {e}")
|
|
sys.exit(1)
|