sql-compare
raw JSON → 0.2.0 verified Fri May 01 auth: no python
Compare SQL schemas and generate human-readable diffs. Version 0.2.0, released November 2024. Active development, monthly releases.
pip install sql-compare Common errors
error ModuleNotFoundError: No module named 'sql_compare' ↓
cause The package is installed as 'sql-compare' but import uses underscore.
fix
Install with
pip install sql-compare and import with from sql_compare import diff. error AttributeError: module 'sql_compare' has no attribute 'get_diff' ↓
cause Function renamed or removed in newer version.
fix
Use
diff() or diff_files() instead of get_diff(). error TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper ↓
cause Passed a file object to `diff_files()` instead of a file path.
fix
Pass a string file path:
diff_files('file1.sql', 'file2.sql'). Warnings
breaking In version 0.2.0, the return type of `diff()` changed from a string to a list of change objects. Code expecting a string will break. ↓
fix Use `get_diff()` for human-readable string output, or iterate over the list objects returned by `diff()`.
deprecated The function `get_diff()` is deprecated in 0.2.0; use `diff()` or `diff_files()` instead. ↓
fix Replace `get_diff(a, b)` with `str(diff(a, b))` or similar.
gotcha `diff_files()` expects file paths, not file objects. Passing an open file handle will fail. ↓
fix Always pass string paths: `diff_files('schema1.sql', 'schema2.sql')`.
Imports
- diff wrong
from sqlcompare import diffcorrectfrom sql_compare import diff - diff_files wrong
from sql_compare.diff import diff_filescorrectfrom sql_compare import diff_files
Quickstart
from sql_compare import diff
schema1 = "CREATE TABLE users (id INT, name TEXT);"
schema2 = "CREATE TABLE users (id INT, name VARCHAR(255));"
print(diff(schema1, schema2))