Skip to content

feat(tables): add reference columns - #7105

Open
j15z wants to merge 10 commits into
stagingfrom
feat/table-fks
Open

feat(tables): add reference columns#7105
j15z wants to merge 10 commits into
stagingfrom
feat/table-fks

Conversation

@j15z

@j15z j15z commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Tables can now store row IDs in a Reference column configured against another table in the same workspace. The type is preserved through table contracts and write paths, while the grid provides sidebar configuration, row-ID copying, and direct navigation to the referenced table.

Stack

This is the foundation layer of the Reference-row stack. #7106 adds inline referenced-row inspection on top of it.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • bun run type-check
  • bun run check:api-validation
  • Focused table contract, column metadata, registry, service, and grid tests

Reviewers should focus on Reference metadata ownership, column conversion behavior, and the create/edit sidebar flow.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

Not attached. The create, configure, rename, copy-row-ID, and reference-navigation flows were exercised locally.

Post-Deploy Monitoring & Validation

  • Create and edit Reference columns against several workspace tables.
  • Confirm stored row IDs remain unvalidated strings and survive reloads and column renames.
  • Watch table contract-validation and row-write errors for Reference metadata regressions.

@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 26, 2026 5:17pm

Request Review

@j15z j15z changed the title feat/table fks feat(tables): add reference columns Aug 26, 2026
@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds Reference table columns across contracts, persistence, conversion, Copilot tooling, undo metadata, and the table editor. It also adds row-ID copying and revises column-header selection, configuration, and inline rename behavior.

  • Registers Reference as a string-backed column type with same-workspace active-target validation.
  • Adds Reference creation, editing, navigation, import, API, and Copilot support.
  • Generalizes type-specific metadata snapshots used when undoing column deletion.
  • Adds column-header interaction and row-context-menu improvements with accompanying tests.

Confidence Score: 3/5

The PR should not merge until reference-target archival is coordinated and failed inline renames stop leaving invalid undo history.

A referenced table can be archived after validation, leaving persisted navigation to an inaccessible target, and a rejected rename retains an undo action despite the mutation rollback.

Files Needing Attention: apps/sim/lib/table/column-types/registry.server.ts, apps/sim/lib/table/service.ts, apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/table-grid.tsx

Important Files Changed

Filename Overview
apps/sim/lib/table/column-types/registry.server.ts Adds active same-workspace target validation, but the resulting invariant is not maintained when a referenced target is archived.
apps/sim/lib/table/columns/service.ts Adds Reference metadata validation and schema-only target updates with transactional persistence.
apps/sim/lib/table/orchestration/columns.ts Routes Reference conversions and target-only updates through the appropriate typed mutation paths.
apps/sim/lib/api/contracts/tables.ts Extends internal table contracts with bounded Reference target IDs and type-specific cross-field validation.
apps/sim/lib/api/contracts/v2/tables.ts Adds Reference metadata to strict public create and update schemas.
apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/table-grid.tsx Adds Reference navigation and inline rename behavior, but failed renames leave unapplied actions in undo history.
apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/column-config-sidebar/column-config-sidebar.tsx Adds target-table selection for Reference columns and moves renaming out of the configuration sidebar.
apps/sim/hooks/use-table-undo.ts Generalizes deleted-column restoration to preserve all registered type metadata.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Create or update Reference column] --> B[Validate active target in workspace]
  B --> C[Persist referenceTableId]
  C --> D[Render Reference column action]
  D --> E[Navigate to target table]
  C --> F[Target table archived]
  F --> G[Source reference remains unchanged]
  G --> H[Navigation cannot load archived target]
Loading

Reviews (1): Last reviewed commit: "improvement(tables): rename columns on d..." | Re-trigger Greptile

and(
eq(userTableDefinitions.workspaceId, workspaceId),
inArray(userTableDefinitions.id, referencedTableIds),
isNull(userTableDefinitions.archivedAt)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Archival breaks reference targets

When a referenced table is archived, the source column retains its referenceTableId even though target validation requires an active table, causing the new navigation action to open a target that the normal table loader excludes.

Comment on lines 1491 to 1493
onSave: (columnName, newName) => {
const oldName = columnsRef.current.find((c) => c.key === columnName)?.name ?? columnName
pushUndoRef.current({ type: 'rename-column', oldName, newName, columnId: columnName })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Failed renames pollute undo

When the server rejects a column rename, this callback leaves the preemptively pushed rename-column action in history even though the optimistic cache update is rolled back, causing a later undo or redo to consume and replay a rename that never succeeded.

Knowledge Base Used: Web application and product surfaces

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 42 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

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