Skip to main content

comdab — Compare Database Schemas

PyPI - Python Version PyPI - Version GitHub Actions Workflow Status Read the Docs PyPI - Types

comdab allows you to compare in depth two database schemas to find all differences: missing columns, different nullabilities or defaults, slight changes in function or triggers definitions...

Installation

Use pip to install comdab:

pip install comdab

Requirements

Goals

comdab allows you to compare in depth two database schemas to find all differences (missing columns, different nullabilities or defaults, slight changes in function or triggers definitions...) and turn these reports into model migrations.

comdab migration generation supercharges migration tools like Alembic to create migrations that, when applied to an existing database, produce the exact same schema than a new database created from scratch.

Indeed, while migration tools can auto-detect model changes and write automatically the migrations to apply to pre-existing databases, it does not cover the whole schema complexity, and does not prevent human errors (like modifying the model without re-generating migrations, or manually editing migrations in a slightly wrong way...)

This may cause dangerous and hard to spot bugs, especially if your unit tests and CI run on a fresh database created from the Python-written model, and not on pre-existing databases with the new migration applied.

By running comdab, you can ensure the two are the nearly-exact same.

comdab is based on the wonderful SQLAlchemy library to connect to the database, and for most of schema introspection.

Usage

Comparing database schemas

comdab main reporting function is .compare_databases, which needs already established SQLAlchemy connections to the two databases to compare:

from comdab import compare_databases
from sqlalchemy import create_engine

engine_1 = create_engine("postgresql://user:pass@host/foo")
engine_2 = create_engine("postgresql://user:pass@host/bar")

with engine_1.connect() as left_conn, engine_2.connect() as right_conn:
    reports = compare_databases(left_conn, right_conn)

if reports:
    print("❌ Database schemas are different:", reports)
else:
    print("✅ Database schemas are the same!")

Generating migrations

To generate migrations, a user-defined MigrationGeneratorPort / PartialMigrationGeneratorPort subclass is additionally needed:

from comdab import generate_migrations, PartialMigrationGeneratorPort
from comdab.models import ComdabTable
from sqlalchemy import create_engine

class MyMigrationGenerator(PartialMigrationGeneratorPort):
    def __init__(self) -> None:
        self.sql_text = ""

    def create_table(self, *, table: ComdabTable) -> None:
        self.sql_text += f"CREATE TABLE {table.name} [...];\n"

    def drop_table(self, *, table: ComdabTable) -> None:
        self.sql_text += f"DROP TABLE {table.name};\n"

    ...

generator = MyMigrationGenerator()
engine_1 = create_engine("postgresql://user:pass@host/source")
engine_2 = create_engine("postgresql://user:pass@host/target")

with engine_1.connect() as source_conn, engine_2.connect() as target_conn:
    generate_migrations(source_conn, target_conn, generator)

print(generator.sql_text)

Advanced usage

See documentation for configuration and other details.

Contributing

Issues and pull requests are welcome!

License

This work is shared under the MIT license.

@ 2025 Loïc Simon (loic.simon@espci.org)

Metadata

Release files for comdab 0.4.2

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

Source distribution (sdist)

Source distribution for comdab 0.4.2
File Size Uploaded Provenance Actions
comdab-0.4.2.tar.gz 89.1 kB With provenance Details for comdab-0.4.2.tar.gz

Built distribution (wheel)

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

Total release size: 122.0 kB

Release files / comdab-0.4.2.tar.gz

Download URL comdab-0.4.2.tar.gz
Size 89.1 kB
Tags Source
SHA-256 checksum
How to use checksums
19870d4eb62d91f0765ae30eb61a77f4d29b4e9662586761d4040c32a068e187
BLAKE2b-256 checksum
How to use checksums
c9283979b224628d408b488da1ee10c31e25b21b339ad456863fc896830aa525
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / comdab-0.4.2-py3-none-any.whl

Download URL comdab-0.4.2-py3-none-any.whl
Size 32.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07cd759a8c3a5f93a316746d29fb1cc3de94ed2b095f9e07e1af34fcd1168ccf
BLAKE2b-256 checksum
How to use checksums
9f59d904bb58d20d561de5c73993a1fb0c1765724efc60f72c4149cf074c7883
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for comdab 0.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for comdab-0.4.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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