Skip to main content

DDLCheck

PyPI version CI Coverage Status License

DDLCheck is a tool that scans PostgreSQL SQL migration files for potentially risky operations that could cause downtime, data loss, or other issues in production environments.

Overview

Database migrations can be risky, especially in production environments with large tables and high traffic. DDLCheck analyzes your SQL migrations to identify operations that:

  • Cause table rewrites (ALTER COLUMN TYPE, DROP COLUMN)
  • Acquire excessive locks (non-CONCURRENT indexes, SET NOT NULL)
  • May lead to data loss (DROP TABLE, TRUNCATE)
  • Affect all rows without filtering (UPDATE without WHERE)

Installation

# Install with pip
pip install ddlcheck

# Or with Poetry
poetry add ddlcheck

Usage

# Check a single SQL file
ddlcheck check migration.sql

# Check a directory of SQL files
ddlcheck check migrations/

# Exclude specific checks
ddlcheck check migrations/ --exclude add_column_not_null_default,drop_table

# List all available checks
ddlcheck list-checks

# Show version
ddlcheck version

Example Output

File: migration.sql
┏━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Line ┃ Severity ┃ Check      ┃ Message                                                                  ┃
┡━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 1    │ HIGH     │ add_column_not_null_default │ Column 'email_verified' added to table 'users' with NOT NULL and DEFAULT │
└──────┴──────────┴────────────┴──────────────────────────────────────────────────────────────────────────┘

Suggestion for add_column_not_null_default (line 1):
Consider using two separate migrations:
1. First add the column with a DEFAULT but as nullable
2. After data has been populated, add the NOT NULL constraint

Available Checks

DDLCheck includes multiple checks for common risky operations:

  • High Severity:

    • add_column_not_null_default: Detects when columns are added with NOT NULL constraints and DEFAULT values
    • alter_column_type: Detects ALTER COLUMN TYPE operations that require table rewrites
    • drop_table: Detects DROP TABLE operations that could result in data loss
    • truncate: Detects TRUNCATE operations which can cause data loss and locks
    • update_without_filter: Detects UPDATE statements without WHERE clauses
  • Medium Severity:

    • create_index: Detects index creation without the CONCURRENTLY option
    • drop_column: Detects DROP COLUMN operations that require table rewrites
    • rename_column: Detects column renames that can break dependent objects
    • set_not_null: Detects when NOT NULL constraints are added to existing columns

Configuration

You can configure DDLCheck using a .ddlcheck file in TOML format:

# List of check IDs to disable
excluded_checks = ["drop_table", "truncate"]

# Override severity levels
[severity]
create_index = "LOW"
add_column_not_null_default = "HIGH"

# Individual check configurations
[create_index]
ignore_non_concurrent = false
min_size_warning = 1000

Documentation

For more detailed documentation, please visit our documentation site.

Contributing

Contributions are welcome! See CONTRIBUTING.md for more information on how to get started.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Metadata

Release files for ddlcheck 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ddlcheck 0.1.0
File Size Uploaded
ddlcheck-0.1.0.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ddlcheck 0.1.0
File Interpreter ABI Platform
ddlcheck-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.9 kB

Release files / ddlcheck-0.1.0.tar.gz

Download URL ddlcheck-0.1.0.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
81cc976bee1795329f5d0fb0f5e6eba408fa14b4ddc9528abdc3b9ee55a3e8ea
BLAKE2b-256 checksum
How to use checksums
172896d9639af9cc9731ba92848659943553c4657c53338f5abc818b78c99188
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.9.19 Darwin/24.0.0

Release files / ddlcheck-0.1.0-py3-none-any.whl

Download URL ddlcheck-0.1.0-py3-none-any.whl
Size 23.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd2414ff99f8d44a93ac89c38a2e1d71dd3d84b02596e6273af17019122fd437
BLAKE2b-256 checksum
How to use checksums
3be924f128e967d79aed1c77803010e93cd243a56ff7c94f998097ca8cfa12bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.9.19 Darwin/24.0.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page