Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f024cc6
Exclude defaults when dumping schema to dict
JeremyMcCormick Mar 12, 2025
3b072ce
Fix indentation
JeremyMcCormick Mar 12, 2025
76f394e
Add option for specifying a list of tables to filter on when comparing
JeremyMcCormick Mar 12, 2025
552be38
Fix displaying the ID of the changed object
JeremyMcCormick Jul 1, 2025
278e44b
Rewrite the `diff` module module so that it emits JSON ouput
JeremyMcCormick Jul 1, 2025
d7783d6
Add support for printing diff output to a file
JeremyMcCormick Jul 1, 2025
a9706e1
Add click to intersphinx links
JeremyMcCormick Jul 2, 2025
7360a99
Return the command result from run_cli() function
JeremyMcCormick Jul 2, 2025
57727b1
Fix cli tests after updating diff module
JeremyMcCormick Jul 2, 2025
c667b6f
Improve the error handling when generating a diff against a database
JeremyMcCormick Jul 2, 2025
efd349f
Add import of data model classes
JeremyMcCormick Jul 2, 2025
c56ba05
Remove SchemaDiff from felis imports
JeremyMcCormick Jul 3, 2025
e117b02
Add an additional attribute to diff test schema
JeremyMcCormick Jul 9, 2025
31b9098
Update the display of the path
JeremyMcCormick Jul 9, 2025
f2196fb
Update diff test files
JeremyMcCormick Jul 9, 2025
0758e5f
Refactor diff module to use classes for handling diff changes
JeremyMcCormick Jul 9, 2025
05df277
Comment out test assertions until fixed
JeremyMcCormick Jul 10, 2025
930dcc9
Turn on id generation to fix several cli tests
JeremyMcCormick Jul 12, 2025
4c5bcbc
Add back deepcopy to avoid altering the original objects
JeremyMcCormick Jul 24, 2025
1a7188f
Update and fix tests of diff module
JeremyMcCormick Jul 24, 2025
960d026
Add news fragment
JeremyMcCormick Jul 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changes/DM-49446.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The ``diff`` module was completely overhauled based on best practices for using the ``deepdiff`` library.
The formatted differences are now displayed in a JSON format, which is more readable and structured than the previous print outs.
A number of bugs and issues with the comparison logic and the display of the diffs were also fixed, improving the accuracy of the schema diffs.
The error handling in the database diff class was improved so that exception messages should be more informative and helpful.
A command line option has been added for writing the diff output to a file.
Finally, an additional command line option allows filtering only on specified tables in the two schemas being compared.
1 change: 1 addition & 0 deletions docs/documenteer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ python_api_dir = "dev/internals"
python = "https://docs.python.org/3"
sqlalchemy = "https://docs.sqlalchemy.org/en/latest"
lsst = "https://pipelines.lsst.io/v/weekly"
click = "https://click.palletsprojects.com"
16 changes: 14 additions & 2 deletions python/felis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from .datamodel import Schema
from .datamodel import (
CheckConstraint,
Column,
ColumnGroup,
Constraint,
DataType,
ForeignKeyConstraint,
Index,
Schema,
SchemaVersion,
Table,
UniqueConstraint,
)
from .db.schema import create_database
from .diff import DatabaseDiff, FormattedSchemaDiff, SchemaDiff
from .diff import DatabaseDiff, FormattedSchemaDiff
from .metadata import MetaDataBuilder

from importlib.metadata import PackageNotFoundError, version
Expand Down
16 changes: 15 additions & 1 deletion python/felis/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,23 @@ def validate(
default="deepdiff",
)
@click.option("-E", "--error-on-change", is_flag=True, help="Exit with error code if schemas are different")
@click.option("--table", "tables", multiple=True, help="Table names to filter on.")
@click.option(
"--output-file",
"-o",
type=click.File(mode="w"),
help="Write diff output to a file insteading of printing",
default=None,
)
@click.argument("files", nargs=-1, type=click.File())
@click.pass_context
def diff(
ctx: click.Context,
engine_url: str | None,
comparator: str,
error_on_change: bool,
tables: list[str],
output_file: IO[str] | None,
files: Iterable[IO[str]],
) -> None:
schemas = [
Expand All @@ -447,20 +457,24 @@ def diff(
diff: SchemaDiff
if len(schemas) == 2 and engine_url is None:
if comparator == "alembic":
if tables:
raise click.ClickException("Table filtering is not supported for Alembic comparator")
db_context = create_database(schemas[0])
assert isinstance(db_context.engine, Engine)
diff = DatabaseDiff(schemas[1], db_context.engine)
else:
diff = FormattedSchemaDiff(schemas[0], schemas[1])
elif len(schemas) == 1 and engine_url is not None:
if tables:
raise click.ClickException("Table filtering is not supported for database comparison")
engine = create_engine(engine_url)
diff = DatabaseDiff(schemas[0], engine)
else:
raise click.ClickException(
"Invalid arguments - provide two schemas or a schema and a database engine URL"
)

diff.print()
diff.print(output_file)

if diff.has_changes and error_on_change:
raise click.ClickException("Schema was changed")
Expand Down
Loading
Loading