CSV Deduplication
When users import CSVs (manually or via Chrome extension), the system prevents duplicate records.Deduplication Keys
| Data Type | Unique Key | Strategy |
|---|---|---|
| Trip Earnings | (user_id, reservation_id) | Upsert — update existing on conflict |
| Earnings Reports | (user_id, composite_key) | Upsert — update existing on conflict |
| Toll Transactions | (provider, date, amount, plaza) | Skip — ignore duplicates |
Trip Earnings Deduplication
Each Turo trip has a uniquereservation_id. When importing:
- Check if a trip with the same
(user_id, reservation_id)exists - If yes → update the existing record (trip details may change, e.g., status Completed → Paid)
- If no → insert a new record
- This is done in batch upserts of 500 rows
Import Superseding
When a new CSV is imported:- A new
csv_importsaudit record is created with statusactive - Previous imports of the same type are marked as
superseded - The actual trip/earning records remain — they’re upserted, not replaced
- This provides an audit trail of import history
Chrome Extension Sync
The Chrome extension follows the same deduplication logic:- Extension scrapes Turo page → sends CSV content
- Server parses CSV identically to manual upload
- Same upsert logic applies
- Import record is tagged with
chrome_extensionin the filename - The Data Sources page shows “Last synced: 2h ago” from the import record
Re-Import Safety
It is safe to re-import the same CSV multiple times:- Existing records are updated (not duplicated)
- New records are inserted
- Import count shows “X new, Y updated”
- No data loss or corruption occurs