Remove dedupeHash and duplicate skipping from CSV upload
Drop dedupeHash field and unique constraint from Transaction model. Remove skipDuplicates from createMany. All rows in every upload are now inserted unconditionally. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -63,11 +63,9 @@ model Transaction {
|
||||
type TransactionType
|
||||
category String?
|
||||
notes String?
|
||||
dedupeHash String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([dedupeHash])
|
||||
@@index([accountId, date])
|
||||
@@index([date])
|
||||
@@index([budgetId])
|
||||
|
||||
@@ -126,9 +126,7 @@ export async function POST(req: Request) {
|
||||
type: r.type,
|
||||
category: r.category ?? null,
|
||||
budgetId: r.budgetId,
|
||||
dedupeHash: r.dedupeHash,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
})
|
||||
|
||||
const skippedCount = normalized.length - importedCount
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { createHash } from 'crypto'
|
||||
import type { NormalizerConfig } from './bank-profiles'
|
||||
|
||||
export interface NormalizedRow {
|
||||
@@ -7,7 +6,6 @@ export interface NormalizedRow {
|
||||
amountCents: number
|
||||
type: 'DEBIT' | 'CREDIT'
|
||||
category?: string
|
||||
dedupeHash: string
|
||||
}
|
||||
|
||||
export function parseCents(raw: string): number {
|
||||
@@ -51,18 +49,6 @@ function strategyB(
|
||||
return { amountCents: Math.abs(parseCents(creditRaw)), type: 'CREDIT' }
|
||||
}
|
||||
|
||||
function dedupeHash(
|
||||
accountId: string,
|
||||
date: Date,
|
||||
description: string,
|
||||
amountCents: number,
|
||||
): string {
|
||||
const dateStr = date.toISOString().split('T')[0]
|
||||
return createHash('sha256')
|
||||
.update(`${accountId}|${dateStr}|${description}|${amountCents}`)
|
||||
.digest('hex')
|
||||
}
|
||||
|
||||
export function normalizeRows(
|
||||
rows: Record<string, string>[],
|
||||
accountId: string,
|
||||
@@ -100,7 +86,6 @@ export function normalizeRows(
|
||||
amountCents,
|
||||
type,
|
||||
category: rawCategory || undefined,
|
||||
dedupeHash: dedupeHash(accountId, date, description, amountCents),
|
||||
})
|
||||
} catch {
|
||||
// skip unparseable rows
|
||||
|
||||
Reference in New Issue
Block a user