Skip to content

feat(tables): upload csvs#3607

Merged
icecrasher321 merged 5 commits intostagingfrom
feat/tables-csv
Mar 16, 2026
Merged

feat(tables): upload csvs#3607
icecrasher321 merged 5 commits intostagingfrom
feat/tables-csv

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Upload CSVs to make tables.

Type of Change

  • New feature

Testing

Tested manually

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)

@cursor
Copy link

cursor bot commented Mar 16, 2026

You have used all 50 Bugbot PR reviews included in your free trial for your GitHub account on this workspace.

To keep getting Bugbot reviews, enable Bugbot for your team in the Cursor dashboard.

@vercel
Copy link

vercel bot commented Mar 16, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 16, 2026 11:23pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 16, 2026

Greptile Summary

This PR adds CSV/TSV upload support to the Tables feature, allowing users to import files via a new header button or right-click context menu. It introduces a new API route (/api/table/import-csv) that handles schema inference, column sanitization, type coercion, and batched row insertion, alongside a new useUploadCsvToTable React Query mutation hook and the necessary UI wiring in the tables list view.

Key observations:

  • The API route properly addresses previously flagged concerns: file size is guarded (50 MB limit), TSV delimiter is inferred from the file extension, and invalid date values are handled gracefully.
  • useUploadCsvToTable skips the response.ok check before parsing JSON, inconsistent with every other mutation hook in the same file — a non-JSON error response (e.g. framework-level 500) will surface an opaque SyntaxError rather than a meaningful message.
  • If any batch row insertion fails after the table has already been created, the table persists in the database (empty or partial) while the client receives an error — there is no rollback or cleanup on partial failure.
  • Upload progress skips the counter for failed files, causing visible jumps in the completed/total display for multi-file batches.
  • The headerActions array is allocated inline in JSX on every render; wrapping it in useMemo would keep the reference stable.

Confidence Score: 3/5

  • Needs fixes before merge — a failed mid-import can leave orphaned tables in the DB, and the mutation hook can produce confusing errors on non-JSON server responses.
  • The core feature logic (schema inference, delimiter handling, batching, auth) is sound, but two logic issues lower confidence: (1) tables can be permanently created even when the import ultimately fails, leaving ghost records; (2) the fetch hook doesn't check response.ok, which diverges from every other hook in the file and produces unhelpful errors on infrastructure-level failures. The UI issues are minor and non-blocking.
  • Pay close attention to apps/sim/app/api/table/import-csv/route.ts (orphaned table on batch failure) and apps/sim/hooks/queries/tables.ts (missing response.ok check).

Important Files Changed

Filename Overview
apps/sim/app/api/table/import-csv/route.ts New API route that parses CSV/TSV files, infers column schema, creates a table, and batch-inserts rows. Well-structured with size limits, auth checks, and delimiter handling, but can leave orphaned tables when batch insertion fails mid-import.
apps/sim/hooks/queries/tables.ts Adds useUploadCsvToTable mutation hook; does not check response.ok before parsing JSON, inconsistent with every other mutation hook in the same file and could surface confusing SyntaxError messages on non-JSON server errors.
apps/sim/app/workspace/[workspaceId]/tables/tables.tsx Adds CSV upload UI with progress tracking, file-input ref, and multi-file loop. Progress counter skips failed files causing visible jumps, and headerActions is recreated on every render.
apps/sim/app/workspace/[workspaceId]/tables/components/tables-list-context-menu/tables-list-context-menu.tsx Adds "Upload CSV" context menu item with onUploadCsv callback and disableUpload prop; straightforward and follows existing component patterns.

Sequence Diagram

sequenceDiagram
    participant User
    participant Tables UI
    participant FileInput
    participant useUploadCsvToTable
    participant POST /api/table/import-csv
    participant DB

    User->>Tables UI: Click "Upload CSV" (button or context menu)
    Tables UI->>FileInput: csvInputRef.click()
    User->>FileInput: Select .csv / .tsv file(s)
    FileInput->>Tables UI: onChange → handleCsvChange()
    Tables UI->>Tables UI: setUploading(true), filter valid files
    loop For each CSV file
        Tables UI->>useUploadCsvToTable: mutateAsync({ workspaceId, file })
        useUploadCsvToTable->>POST /api/table/import-csv: POST FormData (file + workspaceId)
        POST /api/table/import-csv->>POST /api/table/import-csv: auth check, size check, ext check
        POST /api/table/import-csv->>POST /api/table/import-csv: parseCsvBuffer → inferSchema → sanitizeName
        POST /api/table/import-csv->>DB: createTable(name, schema)
        DB-->>POST /api/table/import-csv: table record
        POST /api/table/import-csv->>DB: batchInsertRows (chunks of 1000)
        DB-->>POST /api/table/import-csv: inserted rows
        POST /api/table/import-csv-->>useUploadCsvToTable: { success, data: { table } }
        useUploadCsvToTable->>Tables UI: invalidateQueries(tableKeys.lists())
        Tables UI->>Tables UI: setUploadProgress(i+1 / total)
    end
    Tables UI->>Tables UI: setUploading(false), reset input
    alt Single file upload
        Tables UI->>User: router.push to new table
    else Multiple files, some failed
        Tables UI->>User: toast.error(failed file names)
    end
Loading

Last reviewed commit: 6802bf7

@cursor
Copy link

cursor bot commented Mar 16, 2026

PR Summary

Medium Risk
Adds a new server-side CSV/TSV upload endpoint that parses user-provided files, infers schema, and bulk-inserts rows; parsing/validation and table creation paths can affect performance and data integrity if edge cases slip through.

Overview
Adds CSV/TSV table import: a new POST /api/table/import-csv route accepts a multipart file upload, validates workspace write access, infers a table schema from headers/sample values, creates a new table, and batch-inserts rows (with rollback via table deletion on insert failure).

Exposes the feature in the Tables UI via a new Upload CSV action (header button + list context menu), including multi-file selection, basic progress labeling, error toasts, and navigation to the created table when importing a single file. Also adds a useUploadCsvToTable React Query mutation that posts FormData and invalidates table lists on completion.

Written by Cursor Bugbot for commit df91819. Configure here.

@icecrasher321
Copy link
Collaborator Author

bugbot run

@icecrasher321
Copy link
Collaborator Author

@greptile

@icecrasher321
Copy link
Collaborator Author

bugbot run

@icecrasher321
Copy link
Collaborator Author

bugbot run

@icecrasher321
Copy link
Collaborator Author

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@icecrasher321 icecrasher321 merged commit 6df6512 into staging Mar 16, 2026
12 checks passed
@icecrasher321 icecrasher321 deleted the feat/tables-csv branch March 16, 2026 23:32
emir-karabeg pushed a commit that referenced this pull request Mar 17, 2026
* feat(tables): upload csvs

* address comments

* address comments

* user id attribution

* fix boolean coercion
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