-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_migration.py
More file actions
67 lines (52 loc) · 2.4 KB
/
db_migration.py
File metadata and controls
67 lines (52 loc) · 2.4 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
"""
Database migration utility for the Aerospace Scrap Logbook application.
This script helps migrate data from SQLite to MySQL for better multi-user support.
"""
import os
import argparse
from pathlib import Path
from db_config import DatabaseConfig, migrate_sqlite_to_mysql
def main():
"""
Main function to run the migration utility.
"""
parser = argparse.ArgumentParser(description='Migrate Scrap Logbook data from SQLite to MySQL')
parser.add_argument('--sqlite-path',
help='Path to the SQLite database file (default: network path)',
default='')
parser.add_argument('--mysql-host',
help='MySQL server hostname (default: localhost)',
default='localhost')
parser.add_argument('--mysql-port',
help='MySQL server port (default: 3306)',
default='3306')
parser.add_argument('--mysql-user',
help='MySQL username (default: scrap_user)',
default='scrap_user')
parser.add_argument('--mysql-password',
help='MySQL password (default: scrap_password)',
default='scrap_password')
parser.add_argument('--mysql-database',
help='MySQL database name (default: scrap_logbook)',
default='scrap_logbook')
args = parser.parse_args()
# Determine SQLite path
if args.sqlite_path:
sqlite_path = args.sqlite_path
else:
# Use the network path from the original application
AEROSPACE_BASE = Path(r'X:\AEROSPACE')
sqlite_path = str(AEROSPACE_BASE / 'Aerospace YWG Scrap Parts Logbook' / 'scrap_logbook.db')
# Build MySQL connection string
mysql_connection_string = f"mysql+pymysql://{args.mysql_user}:{args.mysql_password}@{args.mysql_host}:{args.mysql_port}/{args.mysql_database}"
print(f"Starting migration from SQLite ({sqlite_path}) to MySQL ({args.mysql_host}:{args.mysql_port}/{args.mysql_database})")
try:
# Perform the migration
migrate_sqlite_to_mysql(sqlite_path, mysql_connection_string)
print("Migration completed successfully!")
except Exception as e:
print(f"Error during migration: {str(e)}")
return 1
return 0
if __name__ == "__main__":
exit(main())