Skip to content

[P1][bug] Designer doesn't load existing FKs in alter mode — originalConfig.foreignKeys = [] always; existing FKs always re-emit on every save #386

Closed

Description

@EVWorth

Context

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).

Files

  • src/components/designer/TableDesigner.tsx:140-160
  • src-tauri/src/lib.rs:180-230 (invoke_handler missing get_foreign_keys)
  • src-tauri/crates/mas-core/src/schema/inspector.rs (no FK method)
  • docs/design/ARCHITECTURE.md:1037-1045

Repro

  1. CREATE TABLE orders (id INT, user_id INT, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE RESTRICT)
  2. Open Table Designer in alter mode for orders
  3. Foreign Keys tab is empty
  4. Change onDelete to CASCADE on the (now-visible) FK — but it's invisible, so user adds a new FK
  5. Save emits ALTER TABLE orders DROP FOREIGN KEY (none); ADD CONSTRAINT … (the new CASCADE FK)
  6. 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 ….

Needs human verify

yes

Doc drift

yes — ARCHITECTURE §5.3 get_foreign_keys command unimplemented

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/designer
    on Jul 31, 2026
  2. EVWorth commented on Sep 12, 2026

    @EVWorth
    OwnerAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/designerauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions