You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[P1][bug] Designer doesn't load existing FKs in alter mode — originalConfig.foreignKeys = [] always; existing FKs always re-emit on every save #386
Table Designer alter mode loads existing table structure.
Problem
src/components/designer/TableDesigner.tsx:140-160 (alter load useEffect) hardcodes originalConfig.foreignKeys = []. The designer doesn't surface existing FKs to edit them. Adding a new FK works, but: (a) the user has no visibility into existing FKs, (b) every first save sees the existing FKs as "added" (fresh fk-N ID not in empty baseline), (c) every subsequent edit sees the existing FKs as a stable diff (correct after first save), but (d) if the user changes onDelete from RESTRICT to CASCADE, the diff sees a "modify" but the baseline has [] — so the FK appears as "added" with the new action. Root cause: missing getForeignKeys Tauri command (ARCHITECTURE §5.3 signature unimplemented — same as Schema Compare F2).
src-tauri/crates/mas-core/src/schema/inspector.rs (no FK method)
docs/design/ARCHITECTURE.md:1037-1045
Repro
CREATE TABLE orders (id INT, user_id INT, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE RESTRICT)
Open Table Designer in alter mode for orders
Foreign Keys tab is empty
Change onDelete to CASCADE on the (now-visible) FK — but it's invisible, so user adds a new FK
Save emits ALTER TABLE orders DROP FOREIGN KEY (none); ADD CONSTRAINT … (the new CASCADE FK)
The original RESTRICT FK is dropped (lost)
Expected
Loading a table with 2 FKs shows 2 FK rows in the FK tab. Editing the FK onDelete from RESTRICT to CASCADE and saving emits exactly one ALTER TABLE … DROP FOREIGN KEY … and one ADD CONSTRAINT ….
Proposed fix
Add getForeignKeys Tauri command (ARCHITECTURE §5.3 signature). Have the alter useEffect load FKs via api.getForeignKeys(connectionId, database, tableName) and populate originalConfig.foreignKeys. The idCounter-based FK IDs from nextId("fk") need to be persisted into originalConfig.foreignKeys[i].id so the diff matches across saves. Scope: M.
Acceptance
Loading a table with 2 FKs shows 2 FK rows in the FK tab. Editing the FK onDelete from RESTRICT to CASCADE and saving emits exactly one ALTER TABLE … DROP FOREIGN KEY … and one ADD CONSTRAINT ….
Already fixed — closing with the check rather than a change.
The root cause named in the issue — no get_foreign_keys command — is fixed: the command exists, alter mode loads the constraints, and the FK tab shows them. The baseline holds them too, so the four failure modes you enumerated are gone: existing FKs are visible, they do not diff as "added" on first save, and changing ON DELETE from RESTRICT to CASCADE emits exactly one DROP FOREIGN KEY and one ADD CONSTRAINT instead of dropping the original and leaving only the new one.
Activity
fix(designer): show the foreign keys a table already has (#551)
EVWorth commentedon Sep 12, 2026
Already fixed — closing with the check rather than a change.
The root cause named in the issue — no
get_foreign_keyscommand — is fixed: the command exists, alter mode loads the constraints, and the FK tab shows them. The baseline holds them too, so the four failure modes you enumerated are gone: existing FKs are visible, they do not diff as "added" on first save, and changingON DELETEfrom RESTRICT to CASCADE emits exactly one DROP FOREIGN KEY and one ADD CONSTRAINT instead of dropping the original and leaving only the new one.