Skip to content

Commit

Permalink
HCK-6081: fix generate keys by sample if key has changed name
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-filonenko committed May 24, 2024
1 parent f14c9a9 commit 34e70af
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion forward_engineering/services/statements/insertStatements.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ const getInsertScriptForCollection = ({ jsonData, collection }) => {
);

const insertionPath = getKeySpaceReference(collection);
const isKeyGeneratedWithFakerFunction = collection?.properties?.[keyPropertyName]?.fakerFunction;
const parseJsonData = JSON.parse(jsonData);
const sampleValue = collection?.properties?.[keyPropertyName]?.sample;
const keyValue = isKeyGeneratedWithFakerFunction ? parseJsonData[keyPropertyName] : sampleValue;
const { [keyPropertyName]: keyProperty, ...jsonDataBody } = parseJsonData;
const sampledKey = getKeyFieldSample(parseJsonData[keyPropertyName]);

const sampledKey = getKeyFieldSample(keyValue);

return `INSERT INTO ${insertionPath} (KEY, VALUE)\n\tVALUES("${sampledKey}",${JSON.stringify(jsonDataBody, null, '\t')});`;
};
Expand Down

0 comments on commit 34e70af

Please sign in to comment.