fix(cli): Account for unparseable string in JSON key migration (#3927)

 Account for unparseable string in JSON key migration
This commit is contained in:
Iván Ovejero 2022-08-23 17:13:48 +02:00 committed by GitHub
parent f22bd2805d
commit ab45898a69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -64,8 +64,17 @@ export const addJsonKeyToPinDataColumn =
function makeUpdateParams(fetchedWorkflows: PinData.FetchedWorkflow[]) {
return fetchedWorkflows.reduce<PinData.FetchedWorkflow[]>(
(updateParams, { id, pinData: rawPinData }) => {
const pinDataPerWorkflow: PinData.Old | PinData.New =
typeof rawPinData === 'string' ? JSON.parse(rawPinData) : rawPinData;
let pinDataPerWorkflow: PinData.Old | PinData.New;
if (typeof rawPinData === 'string') {
try {
pinDataPerWorkflow = JSON.parse(rawPinData);
} catch (_) {
pinDataPerWorkflow = {};
}
} else {
pinDataPerWorkflow = rawPinData;
}
const newPinDataPerWorkflow = Object.keys(pinDataPerWorkflow).reduce<PinData.New>(
(newPinDataPerWorkflow, nodeName) => {

View file

@ -5,7 +5,7 @@ export namespace PinData {
export type New = { [nodeName: string]: INodeExecutionData[] };
export type FetchedWorkflow = { id: number; pinData: string | object };
export type FetchedWorkflow = { id: number; pinData: string | Old };
}
export function isObjectLiteral(maybeObject: unknown): maybeObject is { [key: string]: string } {