Skip to content

Commit

Permalink
fix: mark as deleted only records from current sync
Browse files Browse the repository at this point in the history
  • Loading branch information
TBonnin committed Mar 21, 2024
1 parent 7b3a6d2 commit 37034c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/shared/lib/services/sync/data/records.service.ts
Expand Up @@ -528,12 +528,18 @@ export async function deleteRecordsBySyncId({ syncId, limit = 5000 }: { syncId:
}

// Mark all non-deleted records that don't belong to currentGeneration as deleted
export async function markNonCurrentGenerationRecordsAsDeleted(connectionId: number, model: string, generation: number): Promise<SyncDataRecord[]> {
export async function markNonCurrentGenerationRecordsAsDeleted(
connectionId: number,
model: string,
syncId: string,
generation: number
): Promise<SyncDataRecord[]> {
return schema()
.from<SyncDataRecord>(RECORDS_TABLE)
.where({
nango_connection_id: connectionId,
model,
sync_id: syncId,
external_is_deleted: false
})
.whereNot({
Expand Down
1 change: 1 addition & 0 deletions packages/shared/lib/services/sync/run.service.ts
Expand Up @@ -406,6 +406,7 @@ export default class SyncRun {
const deletedRecords = await recordsService.markNonCurrentGenerationRecordsAsDeleted(
this.nangoConnection.id as number,
model,
this.syncId as string,
this.syncJobId as number
);
deletedKeys = deletedRecords.flatMap((r) => (r.id ? [r.id] : []));
Expand Down

0 comments on commit 37034c1

Please sign in to comment.