Skip to content

[P1][bug] Designer allows multiple PRIMARY KEY indexes and duplicate index names — produces invalid ALTER TABLE #384

Closed

Description

@EVWorth

Context

Table Designer Indexes tab.

Problem

The Indexes tab lets the user add unlimited indexes with type PRIMARY KEY. MySQL enforces a single primary key per table — ALTER TABLE x ADD PRIMARY KEY (a) after ADD PRIMARY KEY (a) raises ERROR 1068 (42000): Multiple primary key defined. Same for two indexes with the same name. The error surfaces at Save but the user has no client-side guard. There's also no validation that the columns named in a PRIMARY KEY actually exist on the table.

Files

  • src/components/designer/TableDesigner.tsx:550-650 (IndexesTab)
  • src/lib/ddl-generator.ts:206-218

Repro

  1. Create a table with id INT PRIMARY KEY
  2. Open Table Designer in alter mode
  3. Add a second index with type PRIMARY KEY, columns [name]
  4. Click Apply Changes — MySQL returns error 1068

Expected

Adding a second PRIMARY KEY index shows a yellow warning and replaces the prior one. Two indexes with the same name show an inline error. An index referencing a dropped column shows an error.

Proposed fix

Track existing PRIMARY KEYs in component state (primaryKeyColumnIds: Set); when user adds a second PRIMARY KEY index, replace the prior one (delete the old index row, add the new). Validate index name uniqueness client-side (inline error on duplicate name). Validate index columns exist in the table (error if column name not in columnNames). Scope: S.

Acceptance

Adding a second PRIMARY KEY index shows a yellow warning and replaces the prior one. Two indexes with the same name show an inline error. An index referencing a dropped column shows an error.

Needs human verify

no

Doc drift

no

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.

    All three cases now raise an inline amber problem on the index row, before Save:

    • a second index of type PRIMARY KEY — "A table can have only one primary key" (ERROR 1068)
    • a duplicate index name (ERROR 1061)
    • an index naming a column that is not on the table — the case your issue mentioned last and the one that matters most, since it is what a rename leaves behind

    Not implemented: silently replacing the prior primary key when a second is added. Removing something the user did not ask to remove is worse than telling them the two cannot coexist and letting them choose which.

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