From 2d7305df24fc3fa6f3b103311317c1d0ce148f12 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 29 Oct 2026 09:05:42 -0700 Subject: [PATCH] fix(scripts): keep flagging changes to a kept Prisma relation in the schema compatibility check --- scripts/check_schema_compatibility.py | 5 +++-- tests/unit/proxy/test_db_schema_changes.py | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/check_schema_compatibility.py b/scripts/check_schema_compatibility.py index 3cdba7aa1c9..20e65cb986e 100644 --- a/scripts/check_schema_compatibility.py +++ b/scripts/check_schema_compatibility.py @@ -44,9 +44,10 @@ def _model_changes(model: str, old_schema: Schema, new_schema: Schema) -> Iterat if model not in new_schema: yield f"Breaking: Model {model} was removed" return + new_fields: Final = new_schema[model] for field, old_type in old_schema[model].items(): - if not _is_relation(old_type, old_schema): - yield from _field_changes(model, field, old_type, new_schema[model]) + if field in new_fields or not _is_relation(old_type, old_schema): + yield from _field_changes(model, field, old_type, new_fields) def check_breaking_changes(old_schema: Schema, new_schema: Schema) -> tuple[str, ...]: diff --git a/tests/unit/proxy/test_db_schema_changes.py b/tests/unit/proxy/test_db_schema_changes.py index cf8bc6e8098..bbd31b13123 100644 --- a/tests/unit/proxy/test_db_schema_changes.py +++ b/tests/unit/proxy/test_db_schema_changes.py @@ -60,3 +60,12 @@ def test_schema_compatibility_allows_dropping_relations_but_not_their_columns() "Breaking: Field Item.owner_id was removed", "Breaking: Field Item.created_by was removed", ) + + +def test_schema_compatibility_still_rejects_changes_to_a_kept_relation() -> None: + old_creator: Final = 'Owner @relation("Created", fields: [created_by], references: [id])' + new_creator: Final = 'Owner @relation("Created", fields: [created_by], references: [id], onDelete: Restrict)' + restricted: Final = RELATED.replace(old_creator, new_creator) + assert check_breaking_changes(parse_model_fields(RELATED), parse_model_fields(restricted)) == ( + f"Breaking: Field Item.creator changed type from {old_creator} to {new_creator}", + )