-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_database.py
More file actions
84 lines (67 loc) · 2.2 KB
/
reset_database.py
File metadata and controls
84 lines (67 loc) · 2.2 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
Reset Database Helper Script
Use this to delete the database and start fresh if you had import issues
or want to re-import all transactions with different settings.
Usage:
python reset_database.py
Or on Windows:
reset_database.bat
WARNING: This will permanently delete all imported transactions!
"""
import os
import sys
def main() -> None:
"""
Main function to reset the transaction database
Prompts the user for confirmation before deleting transactions.db
"""
db_file = "transactions.db"
print("=" * 70)
print("Reset Transaction Database")
print("=" * 70)
print()
print("⚠️ WARNING: This will DELETE all imported transactions!")
print()
if not os.path.exists(db_file):
print(f"✓ Database file '{db_file}' does not exist.")
print(" No action needed. Just run transaction_manager_gui.py to start fresh.")
print()
return
# Get file size
size_bytes = os.path.getsize(db_file)
size_kb = size_bytes / 1024
print(f"Database file found: {db_file}")
print(f"Size: {size_kb:.2f} KB")
print()
print("This will:")
print(" 1. Delete the existing database")
print(" 2. You'll need to re-import all your CSV files")
print(" 3. Categories will be recreated automatically")
print()
response = input("Are you sure you want to DELETE the database? (yes/no): ").strip().lower()
if response == 'yes':
try:
os.remove(db_file)
print()
print("✓ Database deleted successfully!")
print()
print("Next steps:")
print(" 1. Run: python transaction_manager_gui.py")
print(" 2. Database will be auto-created")
print(" 3. Import your CSV files with correct hash settings")
print()
except Exception as e:
print()
print(f"✗ Error deleting database: {e}")
print()
sys.exit(1)
else:
print()
print("Cancelled. No changes made.")
print()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n\nCancelled by user.")
sys.exit(0)