Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record id should not change between script executions #1893

Merged
merged 1 commit into from Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/shared/lib/services/sync/data/records.service.ts
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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having a namespace hierarchy is not mandatory, we could use a constant root namespace. Let me know what you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be just nango_connection_id yes, otherwise I'm fine with this

};

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