-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql-dataset-migrate.py
More file actions
executable file
·84 lines (66 loc) · 2.12 KB
/
sql-dataset-migrate.py
File metadata and controls
executable file
·84 lines (66 loc) · 2.12 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
#!/usr/bin/env python3
"""
SQL Dataset Migration Script
This script migrates CSV datasets to SQL format.
Usage:
python sql-dataset-migrate.py [--update]
Options:
--update Force update existing SQL files
"""
import sys
import argparse
from pathlib import Path
# Add app directory to path
sys.path.insert(0, str(Path(__file__).parent))
from app.services.csv_to_sql_migrator import CSVToSQLMigrator
def main():
"""Main entry point for the migration script."""
parser = argparse.ArgumentParser(
description='Migrate CSV datasets to SQL format',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python sql-dataset-migrate.py # Migrate all CSV files (skip existing SQL)
python sql-dataset-migrate.py --update # Update all SQL files from CSV
"""
)
parser.add_argument(
'--update',
action='store_true',
help='Force update existing SQL files'
)
parser.add_argument(
'--dataset-dir',
type=str,
default='dataset',
help='Directory containing CSV files (default: dataset)'
)
args = parser.parse_args()
print("=" * 60)
print("CSV to SQL Dataset Migrator")
print("=" * 60)
print()
try:
# Create migrator instance
migrator = CSVToSQLMigrator(dataset_dir=args.dataset_dir)
# Perform migration
sql_files = migrator.migrate_all(force_update=args.update)
if sql_files:
print("\n" + "=" * 60)
print("Success! SQL files generated:")
print("=" * 60)
for sql_file in sql_files:
print(f" ✓ {sql_file.name}")
else:
print("\n" + "=" * 60)
if args.update:
print("No CSV files found to process")
else:
print("All SQL files are up to date")
print("Use --update flag to force regeneration")
print("=" * 60)
except Exception as e:
print(f"\n❌ Error: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
main()