-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmigrate.py
More file actions
168 lines (132 loc) · 4.63 KB
/
migrate.py
File metadata and controls
168 lines (132 loc) · 4.63 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"""
Migration script to backup old application and prepare for new structure
"""
import os
import shutil
import sqlite3
from datetime import datetime
def create_backup():
"""Create backup of current files"""
backup_dir = f"backup_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
print(f"Creating backup in {backup_dir}/")
os.makedirs(backup_dir, exist_ok=True)
# Files to backup
files_to_backup = [
'app_multiuser.py',
'user_auth.py',
'config.py',
'auth.py',
'auth_integration.py'
]
for file in files_to_backup:
if os.path.exists(file):
shutil.copy2(file, backup_dir)
print(f"Backed up: {file}")
# Backup database
if os.path.exists('whatsapp.db'):
shutil.copy2('whatsapp.db', backup_dir)
print("Backed up: whatsapp.db")
print(f"Backup completed in {backup_dir}/")
return backup_dir
def check_database_compatibility():
"""Check if existing database is compatible"""
if not os.path.exists('whatsapp.db'):
print("No existing database found - fresh installation")
return True
try:
conn = sqlite3.connect('whatsapp.db')
cursor = conn.cursor()
# Check for required tables
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
tables = [row[0] for row in cursor.fetchall()]
required_tables = ['app_users', 'contacts', 'messages']
missing_tables = [table for table in required_tables if table not in tables]
if missing_tables:
print(f"Missing tables: {missing_tables}")
print("Database migration may be required")
else:
print("Database appears compatible")
conn.close()
return len(missing_tables) == 0
except Exception as e:
print(f"Database check failed: {e}")
return False
def verify_new_structure():
"""Verify the new application structure is in place"""
required_dirs = [
'app',
'app/models',
'app/services',
'app/routes',
'app/utils'
]
required_files = [
'app/__init__.py',
'app/config.py',
'app/models/__init__.py',
'app/services/__init__.py',
'app/routes/__init__.py',
'app/utils/__init__.py',
'run.py'
]
missing_dirs = [d for d in required_dirs if not os.path.exists(d)]
missing_files = [f for f in required_files if not os.path.exists(f)]
if missing_dirs:
print(f"Missing directories: {missing_dirs}")
return False
if missing_files:
print(f"Missing files: {missing_files}")
return False
print("New application structure verified ✓")
return True
def show_migration_status():
"""Show current migration status"""
print("\n" + "="*50)
print("MIGRATION STATUS")
print("="*50)
# Check old files
old_files = ['app_multiuser.py', 'user_auth.py']
old_exists = [f for f in old_files if os.path.exists(f)]
if old_exists:
print(f"Old files present: {old_exists}")
print("Status: MIGRATION NEEDED")
else:
print("Old files: NOT FOUND")
# Check new structure
new_structure = verify_new_structure()
if new_structure:
print("New structure: READY")
else:
print("New structure: INCOMPLETE")
# Check database
db_compatible = check_database_compatibility()
if db_compatible:
print("Database: COMPATIBLE")
else:
print("Database: NEEDS MIGRATION")
print("="*50)
# Recommendations
if old_exists and new_structure:
print("\nRECOMMENDATION:")
print("1. Test the new application: python run.py")
print("2. If working correctly, remove old files")
print("3. Update your deployment scripts")
elif old_exists:
print("\nRECOMMENDATION:")
print("Complete the restructuring process first")
else:
print("\nSTATUS: Migration appears complete!")
if __name__ == '__main__':
print("WhatsApp Message Hub - Migration Helper")
print("This script helps migrate from the old single-file structure")
print("to the new modular architecture.\n")
# Create backup
backup_dir = create_backup()
# Check current status
show_migration_status()
print(f"\nBackup created in: {backup_dir}")
print("\nNext steps:")
print("1. Test the new application: python run.py")
print("2. Verify all functionality works")
print("3. Update your .env configuration")
print("4. Remove old files when satisfied")