Skip to content

Conversation

@colonelpanic8
Copy link

Summary

This PR adds one_schema and two_schema parameters to the Comparer.compare() method, enabling comparison of specific database schemas rather than using the default schema.

Motivation

When working with PostgreSQL databases that use multiple schemas (e.g., a "railbird" schema instead of the default "public" schema), there was no way to specify which schema to compare. This feature is essential for projects that organize their database objects within named schemas.

Changes

  • Added one_schema and two_schema parameters to Comparer.compare()
  • Updated _get_db_info() to accept and pass schema parameter to inspectors
  • Updated BaseInspector.inspect() abstract method signature to include schema parameter
  • Updated all concrete inspectors to use the schema parameter when calling SQLAlchemy inspector methods:
    • TablesInspector
    • ColumnsInspector
    • PrimaryKeysInspector
    • ForeignKeysInspector
    • IndexesInspector
    • UniqueConstraintsInspector
    • CheckConstraintsInspector
    • EnumsInspector

Usage

from sqlalchemydiff.comparer import Comparer

comparer = Comparer.from_params(db_one_uri, db_two_uri)
result = comparer.compare(
    one_schema="my_schema",
    two_schema="my_schema",
)

Backward Compatibility

The schema parameters default to None, maintaining full backward compatibility with existing code. When None, SQLAlchemy uses the database's default schema behavior.

🤖 Generated with Claude Code

Add one_schema and two_schema parameters to Comparer.compare() method
to allow specifying different database schemas for comparison.

This enables comparing specific schemas within databases that have
multiple schemas, which is common in PostgreSQL setups.

All inspector methods have been updated to pass the schema parameter
to SQLAlchemy's inspector methods (get_table_names, get_columns,
get_pk_constraint, etc.).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant