Repository navigation
Database: the Changes scope keeps what a changed row points at - #127
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
For property-only changes to Order.customerId, the renderer-context traversal omits the owning Customer table, causing the Order → Customer link to disappear from the narrowed model.
1 open issue
What changed in this PR
This PR extends the database renderer’s Changes scope to retain the context needed to read changed rows, addressing missing foreign-key links when only constraint properties change.
Changes:
- Adds
databaseContextto follow key, column, relation, and enum references. - Connects this context to the renderer’s folded Changes scope.
- Adds a regression test for an
onDelete-only change, checking that the referenced table and link remain visible.
| File | Description |
|---|---|
packages/renderers/database/test/diff.test.mjs |
Tests referenced-table and link retention after a foreign-key property change. |
packages/renderers/database/src/scope.ts |
Defines database-specific relationship traversal for scope context. |
packages/renderers/database/src/main.tsx |
Registers databaseContext with the renderer shell. |
Review effort: Balanced
When only a foreign key's properties changed (its onDelete, say), the Changes scope kept the key's own table but not the table it references, so the key had no link. The renderer's scope context now follows a changed row's references, constrains, foreign-key, relation and enum-type relationships: a changed key keeps its referenced table, its columns and the columns they reference, with the link between them, and a changed column the column or enum it refers to. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A column-only change reached the referenced column through its foreign-key link but not that column's table: the shell places only its own context in containers. databaseContext now adds the containers of what it reaches, in either revision. A column-only regression joins the key-only one. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
agorischek
force-pushed
the
agorischek/db-changes-context
branch
from
November 21, 2026 03:22
b0b24a9 to
b7d4b43
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Found by the gallery session. When only a foreign key's properties change (for example its
onDelete), the Changes scope hides the referenced table, so the modified key has nothing to link to. This is the same class of bug as #83: Changes must keep what a changed row needs to be read, and a foreign key needs both ends.Cause. In Prisma and Django extractions a foreign key is a
constraintentity:referencesits target table;constrainsits own columns;foreign-keyrelationship.The shell's Changes context keeps a changed entity's containers (the key's own table) and a changed relationship's endpoints. A key whose only change is a property has no changed relationship, so the scope never reached the referenced table.
Fix. The database renderer gets a scope context,
databaseContextinsrc/scope.ts. From each changed row it followsreferences,constrains,foreign-key,relationandenum-typeoutward. So a changed key keeps:A changed column likewise keeps the column or enum it refers to. Every other column still folds.
Changes scope, prisma-shop with only
Order.customerId'sonDeletechanged:Test. A unit test in
database/test/diff.test.mjsnarrows the model exactly as the shell does (changesScope, then the context, thenscopedModelwith folded parts) and lays out the diff. It checks that Customer is kept and that the key's link runs Order → Customer. Without the fix it fails, keeping only Order.Note, not changed here. A single-column key is drawn as its column's FK marker. In that form its change shows only as the amber marker and status icon, with no "onDelete changed" line, and the All scope shows it the same way. Before this fix, Changes showed the key as a separate row with that line only because its column was hidden.