fix(scripts): keep flagging changes to a kept Prisma relation in the schema compatibility check

This commit is contained in:
mateo-berri 2026-10-29 09:05:42 -07:00
parent 1a4f95d62c
commit 2d7305df24
2 changed files with 12 additions and 2 deletions

View file

@ -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, ...]:

View file

@ -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}",
)