fix(core): Prevent multiple values in the execution metadata for the same key and executionId (#9953)

This commit is contained in:
Danny Martini
2024-07-10 12:47:43 +02:00
committed by GitHub
parent 3a179439c7
commit 2e6b03b2cb
9 changed files with 203 additions and 15 deletions

View File

@@ -6,19 +6,18 @@ import type { ExecutionMetadata } from '@db/entities/ExecutionMetadata';
export class ExecutionMetadataService {
constructor(private readonly executionMetadataRepository: ExecutionMetadataRepository) {}
async save(
executionId: string,
executionMetadata: Record<string, string>,
): Promise<ExecutionMetadata[]> {
const metadataRows = [];
async save(executionId: string, executionMetadata: Record<string, string>): Promise<void> {
const metadataRows: Array<Pick<ExecutionMetadata, 'executionId' | 'key' | 'value'>> = [];
for (const [key, value] of Object.entries(executionMetadata)) {
metadataRows.push({
execution: { id: executionId },
executionId,
key,
value,
});
}
return await this.executionMetadataRepository.save(metadataRows);
await this.executionMetadataRepository.upsert(metadataRows, {
conflictPaths: { executionId: true, key: true },
});
}
}