A comprehensive tool for automatically converting SQL Server T-SQL code to Snowflake SQL with integrated QA testing and Git workflow management.
- Automated Code Conversion: Uses LLM (Claude, GPT, or OpenRouter) to convert T-SQL to Snowflake SQL
- Iterative Review Process: Multiple conversion iterations with LLM-based code review
- Comprehensive QA Testing: Integrated testing using the existing snowflake-qa system
- Git Workflow Management: Automatic feature branch creation, commits, and pull requests
- Database Integration: Direct connection to SQL Server and Snowflake databases
- Object Discovery: Automatic discovery of stored procedures, functions, views, and DDL scripts
- Error Handling & Recovery: Robust error handling with automatic recovery strategies
- Monitoring & Logging: Comprehensive logging and progress monitoring
- Configuration Management: Flexible YAML-based configuration
- Python 3.8+
- GitHub CLI tools (
ghcommand) - Git
- SQL Server access (with integrated security or username/password)
- Snowflake account with SSO or API key authentication
- Anthropic API key (for Claude) OR
- OpenAI API key (for GPT) OR
- OpenRouter API key (for multiple models)
-
Clone or download the tool:
git clone <repository-url> cd automated-conversion
-
Install Python dependencies:
pip install -r requirements.txt
-
Set up environment variables:
# For Anthropic (Claude) export ANTHROPIC_API_KEY="your-api-key-here" # For OpenAI (GPT) export OPENAI_API_KEY="your-api-key-here" # For OpenRouter export OPENROUTER_API_KEY="your-api-key-here"
-
Configure the tool:
- Edit
config.yamlwith your specific settings - Update repository paths, database connections, and LLM preferences
- Edit
The tool uses a comprehensive YAML configuration file (config.yaml) with the following main sections:
global:
max_review_iterations: 3
conversion_timeout_seconds: 300
qa_timeout_seconds: 600
log_level: "INFO"
dry_run: falserepositories:
source_repo: "C:/code/db-staging" # Bitbucket T-SQL objects
target_repo: "C:/gh_code/db-staging" # GitHub Snowflake SQL
qa_repo: "C:/code/snowflake-qa" # Centralized QA configsdatabases:
sql_server:
server: "DB10"
use_integrated_security: true
backup_path: "C:/backups/db-staging.bak"
snowflake:
account: "nmb10465.us-east-1.privatelink"
warehouse: "wh_compute_xm"
role: "DATA_DEVELOPER"
authenticator: "externalbrowser"llm:
provider: "anthropic" # anthropic, openai, openrouter
model: "claude-3-5-sonnet-20241022"
api_key_env: "ANTHROPIC_API_KEY"
max_tokens: 4000
temperature: 0.1-
Check configuration:
python main.py check-config
-
List available objects:
python main.py list-objects
-
Convert all objects:
python main.py convert
-
Convert specific objects:
python main.py convert --objects "dbo.proc1" "dbo.func1"
-
Dry run (no actual conversion):
python main.py convert --dry-run
-
Check conversion status:
python main.py status
-
Use custom configuration:
python main.py convert --config custom_config.yaml
-
Specify output directory:
python main.py convert --output-dir /path/to/output
The tool follows this automated workflow:
- Validates configuration and database connections
- Discovers SQL Server objects to convert
- Initializes Git repositories and QA system
For each object:
- Create feature branch with object name
- Retrieve source code from database or files
- Convert using LLM with iterative review (up to 3 iterations)
- Save converted code to target repository
- Run QA tests (if not dry-run)
- Commit changes with descriptive message
- Create pull request (if QA passes)
- Setup database objects in both SQL Server and Snowflake
- Deploy converted code to respective databases
- Execute procedures and compare outputs
- Run summary/KPI checks and record results
- Run row-level checks and record differences
- Commit changes to feature branch
- Push branch to remote repository
- Create pull request with conversion details
- Clean up temporary objects (if QA passes)
- Stored Procedures: Converted to Snowflake stored procedures
- Functions: Converted to Snowflake UDFs
- Views: Converted to Snowflake views
- DDL Scripts: Table creation and modification scripts
- ETL Scripts: Data manipulation scripts
The tool applies comprehensive conversion rules including:
DECLARE→LETSET @variable = value→LET variable := valueIF EXISTS→IF (EXISTS())BEGIN/ENDblocks → Snowflake syntax
VARCHAR(MAX)→VARCHARDATETIME→TIMESTAMP_NTZBIT→BOOLEANUNIQUEIDENTIFIER→VARCHAR(36)
ISNULL()→IFNULL()LEN()→LENGTH()CHARINDEX()→POSITION()GETDATE()→CURRENT_TIMESTAMP()
- Schema prefix:
STG - Procedure prefix:
SP_ - Function prefix:
FN_ - View prefix:
VW_
The tool integrates with the existing snowflake-qa system to provide:
- Syntax Validation: Basic SQL syntax checks
- Functionality Tests: Parameter and return type consistency
- Performance Tests: Query structure and optimization checks
- Data Validation: Data type and constraint consistency
- Integration Tests: Full end-to-end testing
The tool includes comprehensive error handling:
- Automatic Recovery: Retry strategies for different error types
- Fallback Mechanisms: Alternative approaches when primary methods fail
- Error Categorization: Classification by severity and type
- Detailed Logging: Complete error tracking and reporting
Real-time monitoring includes:
- Progress Tracking: Current object and completion percentage
- Performance Metrics: Processing speed and resource usage
- LLM Usage: Token consumption and API costs
- Error Statistics: Error rates and recovery success
The tool generates several output files:
conversion_log.json: Detailed conversion logerror_log.json: Error tracking and recovery attemptsprogress_report.json: Performance and progress metrics- Converted SQL files in the target repository
-
Database Connection Errors:
- Verify SQL Server server name and authentication
- Check Snowflake account and credentials
- Ensure network connectivity
-
LLM API Errors:
- Verify API key is set correctly
- Check API rate limits and quotas
- Ensure model availability
-
Git Workflow Errors:
- Verify GitHub CLI is installed and authenticated
- Check repository permissions
- Ensure target repository exists
-
QA Test Failures:
- Check database object creation
- Verify data consistency
- Review conversion accuracy
Enable debug logging by setting:
logging:
level: "DEBUG"- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Check the troubleshooting section
- Review the logs for error details
- Create an issue with detailed information
- Include configuration (with sensitive data redacted) and error logs