Skip to main content

CSV Import

HostMetrics supports importing two types of Turo CSV exports. The Data Sources page (/data-sources) provides the upload UI and import history.

Import Types

TypeTabWhat It Contains
Trip EarningsTripEarningsTabPer-trip breakdown with 30+ fields (guest, dates, earnings line items, fees, discounts)
Earnings ReportEarningsReportTabMonthly summary entries from Turo’s earnings report
See Trip Earnings CSV and Earnings Report CSV for full field specifications.

Upload Flow

User selects CSV → FileUploader parses file → Preview shown
→ User confirms → import-service.ts processes rows
→ csv_imports record created → Rows inserted to trips/earnings table
→ Vehicles auto-created if new → Import marked 'active'
  1. File selection — Drag-and-drop or file picker via DataUploadSection
  2. Parsing — CSV is parsed client-side, columns are mapped to expected fields
  3. Preview — User sees a summary of rows, detected year, and any warnings
  4. Import — Rows are inserted with deduplication checks
  5. Confirmation — Import history updates in ImportHistoryTable

Chrome Extension Alternative

Instead of manually downloading CSVs from Turo, the Chrome extension can sync trip data directly. See Chrome Extension Sync for details.

Deduplication

Each imported row generates a checksum from its key fields (reservation ID, dates, amounts). If a row with the same checksum already exists, it is skipped. This makes re-importing the same CSV safe — no duplicate records are created.

Vehicle Auto-Creation

During trip import, if a vehicle name in the CSV does not match any existing vehicle, a new vehicle record is automatically created and linked. This ensures all trips have a valid vehicle_id.

Year Detection and Partitioning

The import system detects the year from trip dates in the CSV. The YearDataTable component shows imported data organized by year, allowing users to manage and delete imports per year.

Audit Trail

Every import creates a csv_imports record containing:
  • File name and type
  • Row count
  • Import timestamp
  • Status (active or deleted)
  • User ID
The ImportHistoryTable displays all past imports with the ability to delete (soft-remove) an import and its associated records.

Error Handling

If a CSV has unexpected columns or missing required fields, the import shows a clear error message before any data is written. Partial imports do not occur — it is all or nothing.

Key Files

FilePurpose
src/lib/db/import-service.tsCore import logic, parsing, dedup, insertion
src/components/data-sources/DataUploadSection.tsxUpload UI with drag-and-drop
src/components/data-sources/TripEarningsTab.tsxTrip earnings import tab
src/components/data-sources/EarningsReportTab.tsxEarnings report import tab
src/components/data-sources/ImportHistoryTable.tsxPast imports with delete
src/components/data-sources/YearDataTable.tsxYear-partitioned data view