Skip to content

feat(frontend): composite primary key support end-to-end (#148)#222

Draft
saurabh500 wants to merge 1 commit into
TabularisDB:feat/sql-serverfrom
saurabh500:feat/148-frontend-composite-pk
Draft

feat(frontend): composite primary key support end-to-end (#148)#222
saurabh500 wants to merge 1 commit into
TabularisDB:feat/sql-serverfrom
saurabh500:feat/148-frontend-composite-pk

Conversation

@saurabh500
Copy link
Copy Markdown
Contributor

Summary

Implements frontend composite primary key support across the stack, resolving #148.

Builds on the SQL Server backend composite PK work in #146/#147. Existing single-PK behavior is preserved; composite-PK tables now display correctly and inline edits route through dedicated composite commands.

Changes

Backend (Rust)

  • models::TableColumn — added pk_ordinal: Option<u32> (1-based position within the PK, matching SQL Server key_ordinal, MySQL SEQ_IN_INDEX, SQLite pragma pk, Postgres kcu.ordinal_position).
  • All four drivers (sqlserver, mysql, postgres, sqlite) now populate pk_ordinal in get_columns and get_all_columns_batch. Postgres reads information_schema.key_column_usage.ordinal_position. View columns are set to None.
  • driver_trait — new default methods update_record_composite and delete_record_composite. When pk_cols.len() == 1 they delegate to the single-PK path; otherwise they return a descriptive error so non-overriding drivers fail loudly instead of corrupting data.
  • Tauri commands — added update_record_composite / delete_record_composite, registered in lib.rs.

Frontend (TypeScript / React)

  • TableColumn type — added pk_ordinal?: number in both src/types/editor.ts and src/types/schema.ts.
  • DataGrid — new optional pkColumns?: string[] prop alongside legacy pkColumn. Builds pkIndexes memo, derives isCompositePk, and routes inline cell updates through update_record_composite when composite. Single-PK path unchanged.
  • Editor.tsx — derives the ordered composite PK list from columnMetadata (filter is_pk, sort ascending by pk_ordinal) and passes it to DataGrid.
  • SchemaDiagram — groups foreign keys by constraint name and styles composite-FK edges distinctly (thicker purple line + constraint label).

Verification

  • cargo check --lib
  • cargo test --lib ✅ 605 passing (2 pre-existing failures in updater::tests unrelated to this PR)
  • npm run typecheck
  • Lint on touched files clean (one pre-existing unrelated error in SchemaDiagram useEffect)

Notes

  • Read-only first. SQL Server remains read-only Phase 1; the default trait error path is sufficient. MySQL / Postgres / SQLite still hit the single-PK delegation when ordinal indicates a true composite, so callers that previously silently used only the first PK column now receive an explicit error instead of corrupting data. A follow-up will add per-driver composite write implementations as needed.
  • Existing single-PK tables: zero behavior change.
  • pk_ordinal is intentionally optional in the TS type so any cached column metadata from older sessions still deserializes.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

…B#148)

- Adds pk_ordinal to TableColumn (Rust + TS) across all four drivers

- New update_record_composite / delete_record_composite trait methods + Tauri commands

- DataGrid accepts pkColumns and routes inline edits through composite invoke

- Editor derives ordered composite PK from columnMetadata and forwards it

- SchemaDiagram groups FK rows by constraint name and styles composite FKs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant