File size: 2,386 Bytes
feca495
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import shutil
import django

# Set up Django settings context
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()

from django.conf import settings
from graphrag.services.neo4j_client import Neo4jClient

def wipe_all_data():
    print("=== STARTING FULL CLEANUP ===")

    # 1. Wipe Neo4j Database
    try:
        print("Connecting to Neo4j...")
        neo4j_client = Neo4jClient()
        print("Wiping all nodes and relationships in Neo4j...")
        neo4j_client.execute_query("MATCH (n) DETACH DELETE n")
        print("βœ“ Neo4j database successfully wiped.")
    except Exception as e:
        print(f"βœ— Failed to wipe Neo4j: {e}")

    # 2. Delete ChromaDB folder
    chroma_dir = settings.CHROMADB_DIR
    if os.path.exists(chroma_dir):
        try:
            print(f"Removing ChromaDB directory: {chroma_dir}...")
            shutil.rmtree(chroma_dir)
            print("βœ“ ChromaDB vectors successfully wiped.")
        except Exception as e:
            print(f"βœ— Failed to delete ChromaDB folder: {e}")
    else:
        print("ChromaDB directory does not exist, skipping.")

    # 3. Delete Uploaded Documents
    media_root = settings.MEDIA_ROOT
    if os.path.exists(media_root):
        try:
            print(f"Emptying media root directory: {media_root}...")
            shutil.rmtree(media_root)
            os.makedirs(media_root, exist_ok=True)
            print("βœ“ Uploaded documents successfully wiped.")
        except Exception as e:
            print(f"βœ— Failed to empty media root: {e}")
    else:
        print("Media root directory does not exist, skipping.")

    # 4. Delete SQLite Database file
    sqlite_db = settings.DATABASES['default'].get('NAME')
    if sqlite_db and os.path.exists(sqlite_db):
        try:
            print(f"Removing SQLite database: {sqlite_db}...")
            os.remove(sqlite_db)
            print("βœ“ Django SQLite database successfully wiped.")
        except Exception as e:
            print(f"βœ— Failed to delete SQLite file: {e}")
    else:
        print("SQLite database file not found, skipping.")

    print("\n=== CLEANUP COMPLETE ===")
    print("To finalize the fresh start, run the migrations to rebuild your database tables:")
    print("  python manage.py migrate")
    print("=========================")

if __name__ == "__main__":
    wipe_all_data()