amo-server/scripts/run_import.py
Maxim Snesarev 33d6bb7ebd Refactor AMO CRM Data Collection Service to use PostgreSQL
- Updated database configuration to switch from SQLite to PostgreSQL, including changes to alembic.ini, Docker Compose, and environment settings.
- Refactored application code to utilize PostgreSQL database adapters, ensuring compatibility with the new database structure.
- Enhanced API routes and data handling to support the new database, including adjustments in data models and query logic.
- Introduced new job processing mechanisms for full synchronization of AMO CRM entities, leveraging FastStream for background tasks.
- Improved logging and error handling across the application to facilitate better monitoring and debugging.
- Removed obsolete SQLite adapter files and migrations, streamlining the project structure for PostgreSQL integration.
2025-11-05 00:38:37 +03:00

119 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""
Simple wrapper script for AMO CRM data import
Provides easy-to-use presets for common import scenarios
"""
import asyncio
import sys
from pathlib import Path
# Add project root to Python path
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
from scripts.import_amocrm_data import AMOCRMImporter
async def run_preset(preset: str):
"""Run import with predefined presets"""
presets = {
'quick': {
'description': 'Quick import - essential data only (users, pipelines, deals)',
'entities': ['users', 'pipelines', 'deals'],
'limit': 100,
'batch_size': 50,
'verbose': True
},
'full': {
'description': 'Full import - all entities with relationships',
'entities': None, # All entities
'limit': 1000,
'batch_size': 100,
'verbose': True
},
'test': {
'description': 'Test import - dry run with sample data',
'entities': None,
'limit': 10,
'batch_size': 5,
'dry_run': True,
'verbose': True
},
'users-only': {
'description': 'Import users only',
'entities': ['users'],
'limit': 500,
'batch_size': 100,
'verbose': True
},
'deals-contacts': {
'description': 'Import deals and related contacts/companies',
'entities': ['users', 'companies', 'contacts', 'deals'],
'limit': 500,
'batch_size': 100,
'verbose': True
}
}
if preset not in presets:
print(f"❌ Unknown preset: {preset}")
print(f"Available presets: {', '.join(presets.keys())}")
return 1
config = presets[preset]
print(f"🚀 Running preset '{preset}': {config['description']}")
print()
# Create importer with preset configuration
importer = AMOCRMImporter(
limit_per_entity=config.get('limit', 1000),
batch_size=config.get('batch_size', 100),
dry_run=config.get('dry_run', False),
force_overwrite=config.get('force', False),
skip_relationships=config.get('skip_relationships', False),
verbose=config.get('verbose', False)
)
# Run import
stats = await importer.import_all_data(config.get('entities'))
# Check for errors
total_errors = sum(s.errors for s in stats.values())
return 1 if total_errors > 0 else 0
def main():
"""Main function"""
if len(sys.argv) != 2:
print("Usage: python scripts/run_import.py <preset>")
print()
print("Available presets:")
print(" quick - Essential data only (users, pipelines, deals)")
print(" full - All entities with relationships")
print(" test - Dry run with sample data")
print(" users-only - Import users only")
print(" deals-contacts - Import deals and related data")
print()
print("For advanced options, use: python scripts/import_amocrm_data.py --help")
return 1
preset = sys.argv[1]
try:
exit_code = asyncio.run(run_preset(preset))
return exit_code
except KeyboardInterrupt:
print("\n❌ Import interrupted by user")
return 1
except Exception as e:
print(f"❌ Import failed: {str(e)}")
return 1
if __name__ == "__main__":
exit_code = main()
sys.exit(exit_code)