SchemaComparison

class sqlcompyre.analysis.schema_comparison.SchemaComparison(engine: Engine, left_schema: str, right_schema: str, left_tables: dict[str, Table], right_tables: dict[str, Table], float_precision: float, collation: str | None, ignore_casing: bool)[source]

Compare the table metadata from two different SQL database schemas.

Note:

This class should never be initialized directly. Use the compare_schemas() function instead.

Attributes:
table_counts

A comparison between the number of tables in each schema.

table_names

A comparison between the table names of the two schemas.

Methods

compare_matched_table(name[, join_columns, ...])

A full comparison between the tables in "left" and "right" schema with the specified name.

summary_report()

Generate a report that summarizes the schema comparison.

table_reports([ignore_tables, ...])

Generate reports for all tables matched between the schemas.

compare_matched_table(name: str, join_columns: list[str] | None = None, ignore_columns: list[str] | None = None, column_name_mapping: dict[str, str] | None = None, infer_primary_keys: bool = False) TableComparison[source]

A full comparison between the tables in “left” and “right” schema with the specified name. The name must be available in table_names.in_common.

Args:
name: The name of the table (possibly including a schema name if this schema comparison

compares multi-part schemas).

join_columns: The columns to join the tables on in order to compare column values. If

not provided, defaults to the union of primary keys. The corresponding primary key(s) of the right table are determined via column_name_mapping.

ignore_columns: Columns to ignore to evaluate equality. These column names should

reference the left table: corresponding columns in the right table are determined via column_name_mapping. Primary key columns passed here are ignored.

column_name_mapping: A mapping from column names in the left table to column names in

the right table. If not provided, defaults to mapping columns with the same names.

infer_primary_keys: Whether primary keys should be inferred if the tables do not have

matching primary key(s).

Returns:

The full comparison between the tables.

summary_report() Report[source]

Generate a report that summarizes the schema comparison.

property table_counts: Counts

A comparison between the number of tables in each schema.

property table_names: Names

A comparison between the table names of the two schemas.

table_reports(ignore_tables: list[str] | None = None, ignore_table_columns: dict[str, list[str]] | None = None, skip_equal: bool = False, infer_primary_keys: bool = False, sort_by: Literal['name', 'creation_timestamp'] = 'name', verbose: bool = True) dict[str, Report][source]

Generate reports for all tables matched between the schemas.

Args:
ignore_tables: A list of regexes specifying tables to ignore completely. Consider

using ^ and $ to match full table names.

ignore_table_columns: A mapping from table names to column names. The provided columns

are ignored to evaluate equality and dropped from all reports. Different to the behavior for ignore_tables, table names are not considered to be regular expressions.

ignore: A mapping from table names to column names. Each table which provides no

column names is ignored completely. If at least one column name is provided, the provided columns are ignored to evaluate equality.

skip_equal: Whether to skip reports about tables which are equal in the two schemas.

Tables that cannot be compared for equality (e.g. because they have no primary key) are still included.

infer_primary_keys: Whether primary keys should be inferred if compared tables do not

have matching primary key(s).

sort_by: The strategy for sorting the table reports. Either alphabetically by the name

of the tables (name) or chronologically by the creation timestamp of the tables in the “left” schema (creation_timestamp). Note that the latter option is not supported for all database systems.

verbose: Whether to show a progress bar for the report generation.

Returns:

A mapping from matched table names to the reports of their comparisons, ordered by the sort strategy.