Skip to content

Commit

Permalink
record id should not change between script executions (NangoHQ#1893)
Browse files Browse the repository at this point in the history
## Describe your changes

Currently the record internal id is modified every time a record is
updated which is counter intuitive and makes debugging harder

With this commit a record id is now a uuid v5 generated from the unique
composite key (connection, model, external id)
  • Loading branch information
TBonnin authored Mar 21, 2024
1 parent d47120c commit 9185b88
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/shared/lib/services/sync/data/records.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export const formatDataRecords = (
trackDeletes = false,
softDelete = false
): ServiceResponse<SyncDataRecord[]> => {
// hashing unique composite key (connection, model, external_id)
// to generate stable record ids across script executions
const stableId = (rawRecord: DataResponse): string => {
const namespace = uuid.v5(`${nango_connection_id}${model}`, uuid.NIL);
return uuid.v5(`${nango_connection_id}${model}${rawRecord.id}`, namespace);
};

const formattedRecords: SyncDataRecord[] = [] as SyncDataRecord[];

const deletedAtKey = 'deletedAt';
Expand Down Expand Up @@ -66,11 +73,10 @@ export const formatDataRecords = (
}
}

const external_id = record['id'];
formattedRecords[i] = {
id: uuid.v4(),
id: stableId(record),
json: record,
external_id,
external_id: record['id'],
data_hash,
model,
nango_connection_id,
Expand Down

0 comments on commit 9185b88

Please sign in to comment.