A comprehensive Python-based utility for orchestrating database migrations from SQL Server to target database platforms. This tool automates the extraction of DDL, transformation of database objects, and deployment to target systems through a workflow-driven approach managed by a Firebird configuration database.
The Database Migration Utility provides an end-to-end solution for migrating SQL Server databases to other platforms. It uses a Firebird database as a central configuration repository to store migration workflows, PowerShell scripts, and Python scripts that orchestrate the migration process. The utility supports phased migrations with separate steps for DDL generation, transformation, and deployment.
- Workflow-Driven Architecture: Multi-step migration workflows stored in Firebird configuration database
- Multi-Database Support: Migrate multiple databases from source to target systems
- Phased Migration: Separate phases for discovery, DDL generation, transformation, and deployment
- Database Blacklisting: Exclude specific databases from migration process
- DDL Generation: Automated extraction of SQL Server DDL using mssql-scripter
- Object-Level Deployment: Deploy tables, table elements (FKs, indexes), and programmability objects separately
- PowerShell Integration: Execute PowerShell scripts dynamically from Firebird database
- Python Script Execution: Run Python scripts stored in the configuration database
- Interactive CLI: User-friendly menu-driven interface with color-coded output
- Comprehensive Logging: Detailed logs for troubleshooting and audit trails
- Error Handling: Continue-on-error options for resilient workflow execution
- Menu Interface (
Menu - Database Migration Utility.py): Interactive CLI for selecting migration operations - Script Executor (
script_executer.py): Core engine that executes workflows, PowerShell scripts, and Python scripts from Firebird - Firebird Configuration Database: Central repository storing workflows, scripts, and migration metadata
- Utility Scripts: Collection of PowerShell and Python scripts for specific migration tasks
- Configuration Files: INI-based configuration for database connections and execution parameters
The script executor supports three execution modes:
- Workflow Mode: Executes a sequence of PowerShell scripts defined in workflow views
- Master Mode: Executes PowerShell scripts from master views for specific operations
- Script Mode: Executes individual Python scripts stored in the database
The Firebird database (DATABASE_MIGRATION_UTILITY_CONFIGURATION_DATABASE.FDB) stores:
- Workflows: Multi-step migration workflows with execution sequences
- Master Views: Collections of PowerShell commands for specific operations
- Python Scripts: Python code stored as text for dynamic execution
- SQL Scripts: SQL commands for database operations
- Server Configurations: Source and target server connection details
- Database Metadata: Information about databases to migrate
Command: Databases
- Connects to source SQL Server instances
- Queries for all available databases
- Imports database list into
IMPORT_DATABASE_INFORMATIONtable - Allows blacklisting of databases to exclude from migration
Command: DDL
- Generates DDL scripts from source SQL Server databases
- Uses mssql-scripter to extract object definitions
- Stores DDL in
Generated_Scripts/directory - Useful for review before migration
Command: Build
- Executes pre-deployment operations
- Transforms DDL for target platform compatibility
- Creates deployment scripts
- Prepares SQL scripts for execution
- Validates object dependencies
Deploy Tables: Tables
- Deploys table DDL to target system
- Creates table structures without constraints
Deploy Table Elements: Elements
- Deploys foreign keys, indexes, and constraints
- Applied after table creation
Deploy Programmability: All
- Deploys views, stored procedures, and functions
- Applied after tables and elements
Command: Full
- Executes complete build and deploy in one operation
- Useful for testing migration process
- Combines all deployment steps
Command: Delete
- Removes generated folders and temporary files
- Cleans up
Generated_Scripts/,Logs/,Output_Files/,SQL_Scripts/
Database_Migration_Utility/
├── Core/
│ ├── Databases/
│ │ └── DATABASE_MIGRATION_UTILITY_CONFIGURATION_DATABASE.FDB
│ ├── Utilities/
│ │ └── [Migration utility scripts]
│ ├── script_executer.py # Core execution engine
│ ├── script_executer_config.ini # Configuration file
│ └── ascii_art.txt # CLI banner
├── Generated_Scripts/ # DDL output from mssql-scripter
├── Logs/ # Execution logs
├── Output_Files/ # Migration output files
├── SQL_Scripts/ # Generated SQL scripts
├── Menu - Database Migration Utility.py # Interactive CLI
└── Reset_Database_Migration_Utility (Drop Folders).py
Key configuration sections:
[Paths]
LOG_DIR: Directory for log filesDB_PATH: Path to Firebird configuration database
[Database]
DB_USER: Firebird username (default: SYSDBA)DB_PASSWORD: Firebird passwordDB_CHARSET: Character set (UTF8)
[Logging]
LOG_LEVEL: Logging verbosity (DEBUG, INFO, WARNING, ERROR, CRITICAL)LOG_FORMAT: Log message formatLOG_FILE_MODE: Append or overwrite logs
[PowerShell]
EXECUTION_POLICY: PowerShell execution policy (Bypass, Unrestricted, etc.)DELETE_TEMP_SCRIPTS: Clean up temporary PowerShell files
[Execution]
CONTINUE_ON_ERROR: Continue workflow on script failureSCRIPT_TIMEOUT: Maximum execution time for scripts
[Database_Queries]
- Table and column names for workflows, master views, and scripts
-
Python 3.7+
python -m pip install --upgrade pip python -m pip install colorama chardet firebird-driver psycopg2-binary
-
Firebird Database 5.0+
- Download: https://firebird.org/
- Or use PowerShell to download:
New-Item -ItemType Directory C:\Temp -Force | Out-Null curl.exe -L "https://sourceforge.net/projects/firebird/files/v5.0.3/Firebird-5.0.3.1683-0-windows-x64.exe/download" ` -o "C:\Temp\Firebird-5.0.3.1683-0-windows-x64.exe"
-
mssql-scripter
- Microsoft's command-line tool for scripting SQL Server objects
- Installation: https://github.com/microsoft/mssql-scripter
- colorama: Terminal color output for CLI
- chardet: Character encoding detection
- firebird-driver: Firebird database connectivity
- psycopg2-binary: PostgreSQL connectivity (for target databases)
Run the menu interface:
python "Menu - Database Migration Utility.py"Menu options:
- Databases: Import source database list
- DDL: Generate DDL scripts only
- Build: Execute pre-deployment build process
- Tables: Deploy table structures
- Elements: Deploy foreign keys and indexes
- All: Deploy views, procedures, and functions
- Full: Complete build and deploy (testing)
- Delete: Clean up generated folders
- Exit: Quit the utility
Execute specific workflows directly:
python Core/script_executer.py <execution_id> <execution_type>Examples:
# Execute workflow ID 1
python Core/script_executer.py 1 workflow
# Execute master view ID 5
python Core/script_executer.py 5 master
# Execute Python script ID 3
python Core/script_executer.py 3 script- SQL Server to PostgreSQL Migration: Migrate databases from SQL Server to PostgreSQL/Babelfish
- Platform Modernization: Move legacy SQL Server databases to cloud platforms
- Database Consolidation: Merge multiple SQL Server instances into a single target
- Environment Cloning: Replicate database structures across environments
- Schema Comparison: Generate DDL for comparison and analysis
- Disaster Recovery: Create portable DDL backups for recovery scenarios
- Test First: Use the
Fullcommand on test databases before production migration - Review DDL: Generate DDL separately to review transformations
- Blacklist Carefully: Exclude system databases and non-migratable databases
- Monitor Logs: Check logs after each step for errors and warnings
- Phased Deployment: Deploy tables, elements, and programmability separately
- Backup Configuration: Regularly backup the Firebird configuration database
- Version Control: Store generated DDL in version control for tracking
- Validate Connections: Test source and target connections before migration
Firebird Connection Errors
- Verify Firebird service is running
- Check username/password in
script_executer_config.ini - Ensure database file path is correct
PowerShell Execution Errors
- Verify execution policy allows script execution
- Check PowerShell version compatibility
- Review logs for specific script errors
mssql-scripter Not Found
- Ensure mssql-scripter is installed and in PATH
- Test mssql-scripter from command line
Migration Failures
- Review logs in
Logs/directory - Check source/target connectivity
- Verify database permissions
All operations are logged with detailed information:
- Log files stored in
Logs/directory - Configurable log levels for verbosity control
- Separate logs for each execution
- Includes timestamps, execution IDs, and error details
- Requires manual configuration of Firebird database workflows
- PowerShell scripts are Windows-specific
- mssql-scripter required for DDL generation
- Some SQL Server features may require manual transformation
- Target platform compatibility depends on DDL transformation scripts
Note: This utility requires proper configuration of the Firebird database with migration workflows and scripts. Consult documentation for setting up workflows and configuring source/target connections.