DatabaseDiff

class felis.diff.DatabaseDiff(schema, engine)

Bases: SchemaDiff

Compare a schema with a database and emit structured differences.

Parameters:
  • schema (Schema) – The schema to compare.

  • engine (Engine) – The database engine to compare with.

Notes

The DatabaseDiff class uses SQLAlchemy to reflect the database schema and compare it with the provided Schema object. It generates a list of differences between the two schemas, which can be printed or converted to a structured format.

The error-handling during the reflection and comparison process is robust, catching various exceptions that may arise from database connectivity issues, invalid configurations, or unexpected errors. This is done because otherwise some obscure errors may be raised during the reflection process and configuration of alembic, which are not very informative to the user.

Methods Summary

print([output_stream])

Print the differences between the schema and the database as JSON.

to_change_list()

Convert database differences to structured format.

Methods Documentation

print(output_stream=None)

Print the differences between the schema and the database as JSON.

Parameters:

output_stream (Optional[IO[str]], default: None) – The output stream for printing the differences.

Return type:

None

to_change_list()

Convert database differences to structured format.

Returns:

List of database change dictionaries.

Return type:

list[dict[str, Any]]