Skip to main content

Detect, classify, and block schema drift in PostgreSQL before your pipelines break

Project description

DriftBrake-Banner

Detect, classify, and block schema drift in PostgreSQL before your pipelines get corrupted.

Tests PyPI Latest Release PyPI Downloads Python License

The tool identifies bugs capable of silently corrupting or breaking pipelines before deploying to production, with a simple concept: you create a "contract" describing exactly how your database should look. Before running any pipeline, the tool compares the actual database against this contract and warns you (or blocks you) if anything has changed.

Consult the documentation: driftbrake.pages


DriftBrake

DriftBrake runs before pipelines execute, verifying that the actual database still respects the contract expected by its data consumers. It detects deviations, classifies impact, and blocks execution when necessary — but never alters the database. DriftBrake is not a migration tool. It doesn't apply changes to the database, doesn't generate SQL scripts, and doesn't manage schema versions.

Python package

This package was designed to run before your pipelines; future updates will expand compatibility to other databases and file formats.

This README contains only basic information related to installing DriftBrake via pip. This package is experimental and may change in future versions. DriftBrake can be used through the CLI or (to customize detection policies) implemented directly in code — see the build instructions in "Python API".

The Python package for DriftBrake automatically reads the current schema of a PostgreSQL database, compares it against a versioned contract, classifies drifts by impact, and can block pipelines before they break in production.

NOTE: If you are using this with a database other than PostgreSQL (MySQL, SQLite, SQL Server, etc.) you may encounter unexpected errors. In the current version DriftBrake is built entirely around PostgreSQL semantics: the schema reader queries information_schema.schemata and reads index options exclusive to Postgres (postgresql_using, postgresql_where), and the type compatibility matrix follows PostgreSQL cast rules (varchar, text, bigint, timestamptz, etc.). Other databases are not supported yet.


Installation

# Installs the psycopg2-binary driver, required for the postgres connection
pip install "driftbrake[postgres]"
# Install pyarrow
pip install "driftbrake[parquet]"

For Parquet files, see the parquet tutorial

The [dev] extra includes pre-commit, ruff, mypy, pytest, and the other development tools.


How it works

The current flow:

schema.lock.json (contract versioned in Git)
        │
        ▼
DriftBrake connects to PostgreSQL
        │
        ▼
reads the current schema automatically
        │
        ▼
compares expected against current
        │
        ├── OK ──────────────────── pipeline runs
        │
        └── BREAKING ────────────── pipeline blocked
                                    ├── displays in terminal
                                    ├── generates schema_diff.json
                                    └── generates schema_report.html

Change types detected

The tool detects the following categories of change in every comparison:

Type What it means
table_added A new table appeared in the database
table_removed A table that existed is gone from the database
column_added A NOT NULL column was added to an existing table
nullable_column_added A nullable column was added to an existing table
column_removed A column was removed from an existing table
type_changed A column's data type changed (e.g. INTEGERTEXT)
nullable_changed The column stopped accepting NULL or started accepting it
default_changed The column's default value changed or was removed
primary_key_changed A column gained or lost its primary key
unique_changed A UNIQUE constraint was added or removed
foreign_key_changed A foreign key was modified
foreign_key_added A foreign key was created where there was none
ordinal_position_changed The column's position in the table changed
possible_rename A column was removed and a similar one was added in the same table. The tool only flags this as a suspicion of rename, never as a confirmation. Always classified as WARNING.

possible_rename is a heuristic, never a confirmation. DriftBrake flags the suspicion when a removed column and an added column appear type-compatible. Final validation must be done by whoever reviews the migration.


possible_rename confidence

Each possible_rename occurrence carries a confidence field indicating how certain the heuristic is:

Level Criteria
high Similar name + same type + close ordinal position (difference ≤ 2)
medium Same type + close ordinal position (difference ≤ 2)
low Only type-compatible (SAFE or WARNING in the type matrix)

Important rules:

  • possible_rename is never automatically classified as BREAKING — always WARNING.
  • A confidence: "high" is still a suspicion, not a certainty.
  • Always review migrations before accepting a rename with driftbrake update-contract.

License

MIT license

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

driftbrake-0.3.0.tar.gz (54.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

driftbrake-0.3.0-py3-none-any.whl (74.3 kB view details)

Uploaded Python 3

File details

Details for the file driftbrake-0.3.0.tar.gz.

File metadata

  • Download URL: driftbrake-0.3.0.tar.gz
  • Upload date:
  • Size: 54.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for driftbrake-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ea35554f0c4e89d3d623060ea25cfd6e98e03db141a3f1f8be1fe74b3648da9e
MD5 b6da739cc0e9f06146c24b7268ff0f94
BLAKE2b-256 6f5c8fd02dcd8a99049ab8c21fe8be3ed002176cf9237802dd1c553d15ddabb0

See more details on using hashes here.

File details

Details for the file driftbrake-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: driftbrake-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 74.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for driftbrake-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 532d92fc7509dce624be6e6d7ec112829a737dcce38193c231c66153be186c0e
MD5 5b1225676a40d9a9f4a11dbf393afb08
BLAKE2b-256 fc82893e36cbaaf02983e1b7c9d2f6b289864e0d90e4ed910fbccfae92b56eee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page