2.1 KiB
2.1 KiB
Convert asyncpg FastAPI project to SQLAlchemy async patterns
This command analyzes a FastAPI project, detects all asyncpg usage patterns, and systematically converts them to SQLAlchemy 2.0+ with async support while maintaining full functionality.
Usage
/convert-asyncpg-to-sqlalchemy [options]
Options
--path <directory>: Project directory to analyze (default: current directory)--backup <directory>: Backup location before conversion (default: ./backup_asyncpg)--supabase: Enable Supabase-specific optimizations and integrations--models-only: Only convert models, skip utility functions--dry-run: Preview changes without modifying files--interactive: Prompt for confirmation on major changes
Process
Phase 1: Detection & Analysis
- Scan all Python files for asyncpg imports and usage patterns
- Analyze connection methods, query patterns, and transaction handling
- Generate detailed conversion report with complexity assessment
Phase 2: Backup Creation
- Create complete backup of original code
- Generate conversion log for rollback capabilities
- Document all detected patterns and planned changes
Phase 3: Systematic Conversion
- Update imports from asyncpg to SQLAlchemy
- Convert connection patterns to async session management
- Transform query syntax (fetch → execute, parameter binding)
- Update transaction handling patterns
- Convert error handling to SQLAlchemy exceptions
Phase 4: Validation
- Syntax validation of converted code
- Import verification and dependency checking
- Basic functionality testing of converted patterns
Phase 5: Documentation
- Generate conversion summary report
- Create migration guide with before/after examples
- Document any manual intervention requirements
Examples
Convert current directory with Supabase support:
/convert-asyncpg-to-sqlalchemy --supabase
Dry run to preview changes:
/convert-asyncpg-to-sqlalchemy --dry-run --path ./my-fastapi-app
Interactive conversion with custom backup:
/convert-asyncpg-to-sqlalchemy --path ./src --backup ./original_code --interactive