File size: 4,949 Bytes
f0b765c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Archive Migration Files Script

This script moves completed migration files to the archive directory
to clean up the main codebase while preserving historical context.

Usage:
    python scripts/archive_migration_files.py [--dry-run]

Options:
    --dry-run    Show what would be moved without actually moving files
"""

import argparse
from pathlib import Path
import shutil
class MigrationArchiver:
    """Handles archiving of completed migration files."""
    
    def __init__(self, dry_run=False):
        self.dry_run = dry_run
        self.root_dir = Path.cwd()
        self.archive_dir = self.root_dir / "archive"
        self.migration_files = [
            "migrate_user_authentication.py",
            "rollback_user_authentication.py", 
            "validate_user_migration.py"
        ]
        self.migration_dirs = [
            "migration_backups"
        ]
        
    def create_archive_structure(self):
        """Create the archive directory structure."""
        if not self.dry_run:
            self.archive_dir.mkdir(exist_ok=True)
            print(f"✓ Created archive directory: {self.archive_dir}")
        else:
            print(f"[DRY RUN] Would create archive directory: {self.archive_dir}")
            
    def archive_file(self, source_path, relative_path=None):
        """Archive a single file to the archive directory."""
        source = Path(source_path)
        if not source.exists():
            print(f"⚠ File not found: {source}")
            return False
            
        if relative_path:
            dest = self.archive_dir / relative_path
        else:
            dest = self.archive_dir / source.name
            
        if self.dry_run:
            print(f"[DRY RUN] Would move: {source} -> {dest}")
            return True
            
        # Create destination directory if needed
        dest.parent.mkdir(parents=True, exist_ok=True)
        
        try:
            shutil.move(str(source), str(dest))
            print(f"✓ Archived: {source} -> {dest}")
            return True
        except Exception as e:
            print(f"✗ Failed to archive {source}: {e}")
            return False
            
    def archive_directory(self, source_path, relative_path=None):
        """Archive an entire directory to the archive directory."""
        source = Path(source_path)
        if not source.exists():
            print(f"⚠ Directory not found: {source}")
            return False
            
        if relative_path:
            dest = self.archive_dir / relative_path
        else:
            dest = self.archive_dir / source.name
            
        if self.dry_run:
            print(f"[DRY RUN] Would move directory: {source} -> {dest}")
            return True
            
        try:
            shutil.move(str(source), str(dest))
            print(f"✓ Archived directory: {source} -> {dest}")
            return True
        except Exception as e:
            print(f"✗ Failed to archive directory {source}: {e}")
            return False
            
    def run_archival(self):
        """Execute the archival process."""
        print("Starting migration file archival process...")
        print(f"Archive directory: {self.archive_dir}")
        print(f"Dry run mode: {self.dry_run}")
        print("-" * 50)
        
        # Create archive structure
        self.create_archive_structure()
        
        # Archive individual migration files
        archived_files = 0
        for file_name in self.migration_files:
            if self.archive_file(file_name):
                archived_files += 1
                
        # Archive migration directories
        archived_dirs = 0
        for dir_name in self.migration_dirs:
            if self.archive_directory(dir_name):
                archived_dirs += 1
                
        print("-" * 50)
        print(f"Archival complete!")
        print(f"Files archived: {archived_files}/{len(self.migration_files)}")
        print(f"Directories archived: {archived_dirs}/{len(self.migration_dirs)}")
        
        if self.dry_run:
            print("\nThis was a dry run. Use without --dry-run to actually move files.")
            
        return archived_files + archived_dirs > 0


def main():
    """Main entry point for the archival script."""
    parser = argparse.ArgumentParser(
        description="Archive completed migration files to clean up codebase"
    )
    parser.add_argument(
        "--dry-run", 
        action="store_true",
        help="Show what would be moved without actually moving files"
    )
    
    args = parser.parse_args()
    
    archiver = MigrationArchiver(dry_run=args.dry_run)
    success = archiver.run_archival()
    
    if not success and not args.dry_run:
        print("⚠ Some files could not be archived. Check the output above.")
        return 1
        
    return 0


if __name__ == "__main__":
    exit(main())