A collection of utility tools for working with various dialects of SQL databases.
-
Object Comparison Tool (
object_compare): Compare definitions of stored procedures, views, functions, tables, triggers, sequences, indexes, types, external tables, and foreign keys across different environments (DEV, QA, UAT, PROD)- Identify exclusive objects that exist in only one environment
- Check for definition differences in objects across environments
-
Stored Procedure Tester (
usp_tester): Batch test execution of stored procedures with configurable parameters- Support for default parameter values
- Execution time tracking
- Different logging levels (summary, verbose)
-
View Tester (
view_tester): Batch test queries against views- Runs a "TOP 1 *" for each view to ensure output is valid
- Execution time tracking
- Different logging levels (summary, verbose)
-
Schema Size (
schema_size): Analyzes storage across databases by measuring schema sizes.- The tool connects to multiple servers, calculates data and index space consumption in megabytes, and generates formatted tabular reports comparing schema sizes.
- Results are displayed with customizable detail levels based on logging preferences.
-
Data Compare (
data_compare): Compare data across different database platforms- Support for MSSQL and PostgreSQL databases
- Compare data using custom SQL queries
- Option to use query files for complex comparisons
- Flexible output options: left_only, right_only, common, differences, or all
- Detailed reporting on differences between datasets
-
Database Diagram Generator (
db_diagram): Generate ERD diagrams from database metadata- Support for DBML (Database Markup Language), Mermaid, and PlantUML formats
- DBML is the default format - purpose-built for database schemas with clean, readable syntax
- Configurable column display modes (all columns, keys only, or table names only)
- Hierarchical diagrams: Focus on relationships around a specific base table with directional traversal
- Automatic relationship detection from foreign key constraints
- Rich console output with progress indicators and formatted results
-
Python 3.13+
-
Appropriate database drivers:
- ODBC Driver for SQL Server (for MSSQL databases)
- More drivers to be added for other database types
-
Clone the repository:
git clone https://github.com/nathanthorell/sql-tools.git cd sql-tools -
Create and activate a virtual environment, then install the package:
make install
Or manually:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -e ".[dev]"
-
Create a
.envfile based on the provided.env.example:cp .env.example .env
Then update the connection strings with your database details.
-
Create a
config.tomlfile for each tool you want to use.
An .env.example file is provided with the repository. Copy this to create your own .env file:
cp .env.example .envThen adjust the connection strings and other settings according to your environment.
The tools will read these environment variables to establish connections to the various SQL instances.
Create a config.toml file in the project root directory based on the provided config-example.toml:
cp config-example.toml config.toml- Object Compare: Set the schema name to compare across environments
- USP Tester: Configure the schema, logging level, and default parameter values for stored procedures
- View Tester: Configure the schema and logging level
- Schema Size: Configure the server connections, databases to compare, and logging level
- Data Compare: Configure named comparison pairs with left/right database connections, database types (MSSQL/PostgreSQL), and queries or query files to compare
- Database Diagram Generator: Configure the connection, schema, column display mode, diagram format, and output settings
object_compareThis will:
- Connect to each configured environment using the specified connection strings
- Compare object definitions across environments for each object type
- Report differences in object definitions using checksums
- Highlight objects that exist in one environment but not others
usp_testerThis will:
- Connect to the configured test database
- Execute all stored procedures in the specified schema
- Apply default parameter values
- Report execution status and timing
view_testerThis will:
- Connect to the configured test database
- Execute all views in the specified schema
- Report execution status and timing
schema_sizeThis will:
- Connect to each server using the specified connection strings
- Calculate size metrics for each database and schema
- Generate reports showing data and index sizes per schema
- Provide comparative summaries across all servers and databases
data_compare- Connect to the configured database sources (supports both MSSQL and PostgreSQL)
- Execute the defined queries against both data sources
- Compare the results of both queries
- Generate a detailed report of matching and non-matching data
- Display performance comparison between execution time of each data source
left_only: Export rows that exist only in the left query resultright_only: Export rows that exist only in the right query resultcommon: Export rows that exist in both query resultsdifferences: Export both left_only and right_only (what's different)all: Export left_only, right_only, and common (complete breakdown)
db_diagramThis will:
- Connect to the configured database using the specified connection string
- Analyze the database schema and extract table/column metadata
- Detect relationships based on foreign key constraints
- Generate diagram code in the specified format (DBML, Mermaid, or PlantUML)
- Save the diagram to the configured output directory with appropriate file extension (.dbml, .mmd, or .puml)
make lint # Run ruff and mypy linters
make format # Format code with ruffmake clean # Remove temporary files and virtual environment