🔍 Code Extractor

function main_v13

Maturity: 48

Command-line interface function that orchestrates database migration from a legacy document AI system to a new architecture, with options for verification and sample data creation.

File:
/tf/active/vicechatdev/vice_ai/migration.py
Lines:
376 - 411
Complexity:
moderate

Purpose

This function serves as the entry point for a migration tool that transfers data from a legacy file-based system to a new database-backed architecture. It provides three operational modes: full migration (default), verification-only mode to check existing migrations, and sample data creation mode for testing. The function parses command-line arguments, instantiates a LegacySystemMigrator, executes the requested operation, and outputs JSON-formatted reports to stdout.

Source Code

def main():
    """Main migration function"""
    import argparse
    
    parser = argparse.ArgumentParser(description='Migrate Complex Document AI Assistant to new architecture')
    parser.add_argument('--data-dir', default='./data', help='Legacy data directory')
    parser.add_argument('--db-path', default='./documents.db', help='New database path')
    parser.add_argument('--create-sample', action='store_true', help='Create sample data instead of migration')
    parser.add_argument('--verify-only', action='store_true', help='Only verify existing migration')
    
    args = parser.parse_args()
    
    migrator = LegacySystemMigrator(args.data_dir, args.db_path)
    
    if args.verify_only:
        report = migrator.verify_migration()
        print("\nVerification Report:")
        print(json.dumps(report, indent=2))
    elif args.create_sample:
        sample_data = migrator.create_sample_data()
        print("\nSample Data Created:")
        print(json.dumps(sample_data, indent=2))
        
        # Also verify
        verification = migrator.verify_migration()
        print("\nVerification Report:")
        print(json.dumps(verification, indent=2))
    else:
        migration_report = migrator.run_migration()
        print("\nMigration Report:")
        print(json.dumps(migration_report, indent=2))
        
        # Verify migration
        verification = migrator.verify_migration()
        print("\nVerification Report:")
        print(json.dumps(verification, indent=2))

Return Value

Returns None (implicit). The function outputs results to stdout as JSON-formatted strings and does not return any value. Side effects include database modifications and console output.

Dependencies

  • argparse
  • json
  • os
  • uuid
  • datetime
  • typing
  • models
  • services

Required Imports

import argparse
import json
import os
import uuid
from datetime import datetime
from typing import Dict, List, Any, Optional
from models import TextSection, Document, DocumentSection, TextSectionVersion, ChatConfiguration, ChatMessage, SectionType, ContentStatus, DatabaseManager
from services import TextSectionService, DocumentService

Conditional/Optional Imports

These imports are only needed under specific conditions:

import argparse

Condition: imported lazily inside the function body, always needed when function executes

Required (conditional)

Usage Example

# Run full migration with default paths
if __name__ == '__main__':
    main()

# Command-line usage examples:
# Full migration with custom paths:
# python script.py --data-dir /path/to/legacy/data --db-path /path/to/new.db

# Create sample data for testing:
# python script.py --create-sample

# Verify existing migration:
# python script.py --verify-only

# Custom paths with verification only:
# python script.py --data-dir ./legacy --db-path ./prod.db --verify-only

Best Practices

  • This function should be called as the main entry point of a script using if __name__ == '__main__': main()
  • Ensure the LegacySystemMigrator class is properly defined before calling this function
  • The function outputs to stdout, so redirect output if you need to capture reports programmatically
  • Always run with --verify-only first on production systems to assess migration impact
  • Use --create-sample for testing the migration process before running on real data
  • The function performs both migration and verification in default mode, which may take time for large datasets
  • Ensure write permissions exist for the database path before running migration
  • The legacy data directory should contain the expected file structure for the LegacySystemMigrator
  • Consider backing up both legacy data and any existing database before running migration

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class LegacySystemMigrator 68.5% similar

    Migrates data from a legacy file-based document system to a new database-backed architecture with TextSection-centric design, including document metadata, sections, chat configurations, and version history.

    From: /tf/active/vicechatdev/vice_ai/migration.py
  • function migrate_from_legacy 60.6% similar

    Flask API endpoint that migrates data from a legacy system to the current database by accepting a data directory path and executing a migration process.

    From: /tf/active/vicechatdev/vice_ai/new_app.py
  • function main_v6 60.1% similar

    Main entry point function for the Contract Validity Analyzer application that orchestrates configuration loading, logging setup, FileCloud connection, and contract analysis execution.

    From: /tf/active/vicechatdev/contract_validity_analyzer/main.py
  • function main_v43 57.6% similar

    Entry point function that parses command-line arguments and orchestrates the FileCloud email processing workflow to find, download, and convert .msg files.

    From: /tf/active/vicechatdev/msg_to_eml.py
  • function main_v24 56.4% similar

    Interactive CLI function that allows users to select and run document processing test scenarios with varying document counts, providing feedback on test success and next steps.

    From: /tf/active/vicechatdev/contract_validity_analyzer/test_real_documents.py
← Back to Browse