Repository navigation
fix(designer): show the foreign keys a table already has - #551
Merged
Merged
Conversation
Closes #385, #386. ## The tab was empty for every table (#386) ForeignKeyInfo existed in the inspector with nothing producing it, no command exporting it and no binding for it — so an existing constraint could not be seen, edited or removed, and the diff baseline was a hardcoded empty list. get_foreign_keys joins KEY_COLUMN_USAGE, which has one row per column, to REFERENTIAL_CONSTRAINTS, which has one row per constraint and carries the ON UPDATE and ON DELETE rules. Rows are grouped by constraint in ORDINAL_ POSITION order, so a composite key keeps its column order — the pairing with the referenced columns is positional, and the wrong order would build a different constraint. ForeignKeyInfo took a single column and a single referenced column, which cannot describe a composite key. It carries both as lists now. Nothing consumed the old shape, so nothing had to be migrated. The designer loads them into the form and into the baseline, so an untouched key is no change and editing ON DELETE emits one DROP and one ADD rather than an unexplained ADD. The issue's repro ends "the original RESTRICT FK is dropped (lost)". It is not: with an empty baseline the diff emits only an ADD, and nothing drops the original. The harm is that the constraint is invisible and unmanageable, which is enough. ## Mismatched types reached the server (#385) MySQL answers `INT REFERENCES VARCHAR(50)` with ERROR 1215, which names neither the column nor the reason. The editor let any local column point at any referenced column, so that error was the first sign. foreignKeyTypeProblem compares type families — integer, decimal, text, binary, temporal — and says which pair cannot work. Deliberately a warning and not a gate: the real rules take in storage engine, character set, index coverage and signedness, and refusing more than the server would is the worse failure. An unrecognised type on either side produces no claim rather than a guess. Referenced columns now carry their type, and a key loaded from the server names a table nobody picked, so the tab asks for that table's columns itself — once per table, since the loader swallows failures and keying off "not loaded yet" would retry every render. ## Tests Four integration tests, two of them per server, covering the actions, a composite key's column order, and a table with no keys at all. Six unit tests on the compatibility check and four on the component; the three component tests asserting new behaviour fail against the previous version. Co-Authored-By: Claude Opus 5 <[email protected]>
EVWorth
added a commit
that referenced
this pull request
Sep 9, 2026
Closes #369, #370, #371, #372, #373, #374. Schema compare could not back the claim it made, and a compare tool that is quietly wrong is worse than none, because people act on its answer. - SchemaSnapshot had no foreignKeys field, so two schemas differing only in their foreign keys compared as identical (#370) - DDL was normalised by lowercasing and collapsing whitespace before being compared, which mangles string literals and identifiers — reporting differences that are not there and missing ones that are (#371) - column order was ignored, so a reorder read as no change (#374) - the sync half ran each statement independently, leaving a target half-migrated when one failed (#369), and built `USE ${database}` by raw string concatenation (#372) Fixing all of that is a real piece of work — a proper DDL comparison rather than string normalisation is most of it — and the feature is not part of how this project is used. Removing it now is cheaper than carrying it, and the history has it if someone wants it back. Gone: SchemaCompare, SyncPreview, schema-diff, sync-sql-generator, their tests, the "compare" editor tab type, and the entry points in the menu bar, title bar and toolbar. 840 lines of feature, about 1,100 with tests. Two things kept deliberately. The test asserting that right-clicking a toolbar button does not open the system menu now right-clicks Admin — it used Compare only because it was there, and the behaviour still matters. And get_foreign_keys stays: the designer uses it, and it was written for the designer in #551. Co-authored-by: Claude Opus 5 <[email protected]>
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.
Closes #385, #386.
The tab was empty for every table — #386
ForeignKeyInfoexisted in the inspector with nothing producing it, no command exporting it and no binding for it. So an existing constraint couldn't be seen, edited or removed, and the diff baseline was a hardcoded empty list.get_foreign_keysjoinsKEY_COLUMN_USAGE(one row per column) toREFERENTIAL_CONSTRAINTS(one row per constraint, carrying the ON UPDATE / ON DELETE rules). Rows are grouped by constraint inORDINAL_POSITIONorder, so a composite key keeps its column order — the pairing with the referenced columns is positional, and the wrong order builds a different constraint.ForeignKeyInfotook a singlecolumnandreferenced_column, which can't describe a composite key. It carries both as lists now; nothing consumed the old shape, so nothing had to be migrated.The designer loads them into the form and the baseline, so an untouched key is no change, and editing ON DELETE emits one DROP plus one ADD rather than an unexplained ADD.
Correction to the issue: its repro ends "the original RESTRICT FK is dropped (lost)". It isn't — with an empty baseline the diff emits only an ADD, and nothing drops the original. The real harm is that the constraint is invisible and unmanageable, which is enough on its own.
Mismatched types reached the server — #385
MySQL answers
INT REFERENCES VARCHAR(50)withERROR 1215, naming neither the column nor the reason. The editor let any local column point at any referenced column, so that error was the first sign.foreignKeyTypeProblemcompares type families — integer, decimal, text, binary, temporal — and says which pair can't work.Deliberately a warning, not a gate. The real rules take in storage engine, character set, index coverage and signedness; a check that refuses more than the server would is a worse failure than one that occasionally lets something through. An unrecognised type on either side produces no claim rather than a guess.
Referenced columns now carry their type. A key loaded from the server names a table nobody picked, so the tab requests that table's columns itself — once per table, since the loader swallows failures and keying off "not loaded yet" alone would retry on every render.
Tests
Four integration tests, two of them run against both servers: the actions come back right, a composite key keeps its column order, and a table with no keys reports none. Six unit tests on the compatibility check, four on the component — the three asserting new behaviour fail against the previous version.
54 integration tests against live servers, 1776 unit + 298 browser, clippy/tsc/dprint/eslint clean.
🤖 Generated with Claude Code