fix(Google Sheets Node): Check for column names changes before upsert, append, update (#9649)

This commit is contained in:
Michael Kret
2024-06-20 16:19:16 +03:00
committed by GitHub
parent cdc2f9e7d3
commit 223488f190
7 changed files with 127 additions and 8 deletions

View File

@@ -1,9 +1,16 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import {
type IExecuteFunctions,
type IDataObject,
type INodeExecutionData,
NodeOperationError,
type ResourceMapperField,
} from 'n8n-workflow';
import type { SheetProperties, ValueInputOption } from '../../helpers/GoogleSheets.types';
import type { GoogleSheet } from '../../helpers/GoogleSheet';
import {
autoMapInputData,
cellFormatDefault,
checkForSchemaChanges,
mapFields,
untilSheetSelected,
} from '../../helpers/GoogleSheets.utils';
@@ -226,6 +233,21 @@ export async function execute(
headerRow = locationDefine.headerRow as number;
}
if (nodeVersion >= 4.4 && dataMode !== 'autoMapInputData') {
//not possible to refresh columns when mode is autoMapInputData
const sheetData = await sheet.getData(sheetName, 'FORMATTED_VALUE');
if (sheetData?.[headerRow - 1] === undefined) {
throw new NodeOperationError(
this.getNode(),
`Could not retrieve the column names from row ${headerRow}`,
);
}
const schema = this.getNodeParameter('columns.schema', 0) as ResourceMapperField[];
checkForSchemaChanges(this.getNode(), sheetData[headerRow - 1], schema);
}
let setData: IDataObject[] = [];
if (dataMode === 'autoMapInputData') {

View File

@@ -1,4 +1,9 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import type {
IExecuteFunctions,
IDataObject,
INodeExecutionData,
ResourceMapperField,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import type {
ISheetUpdateData,
@@ -7,7 +12,11 @@ import type {
ValueRenderOption,
} from '../../helpers/GoogleSheets.types';
import type { GoogleSheet } from '../../helpers/GoogleSheet';
import { cellFormatDefault, untilSheetSelected } from '../../helpers/GoogleSheets.utils';
import {
cellFormatDefault,
checkForSchemaChanges,
untilSheetSelected,
} from '../../helpers/GoogleSheets.utils';
import { cellFormat, handlingExtraData, locationDefine } from './commonDescription';
export const description: SheetProperties = [
@@ -267,6 +276,11 @@ export async function execute(
columnNames = sheetData[headerRow] ?? [];
if (nodeVersion >= 4.4) {
const schema = this.getNodeParameter('columns.schema', 0) as ResourceMapperField[];
checkForSchemaChanges(this.getNode(), columnNames, schema);
}
const newColumns = new Set<string>();
const columnsToMatchOn: string[] =

View File

@@ -1,4 +1,9 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import type {
IExecuteFunctions,
IDataObject,
INodeExecutionData,
ResourceMapperField,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import type {
ISheetUpdateData,
@@ -7,7 +12,11 @@ import type {
ValueRenderOption,
} from '../../helpers/GoogleSheets.types';
import type { GoogleSheet } from '../../helpers/GoogleSheet';
import { cellFormatDefault, untilSheetSelected } from '../../helpers/GoogleSheets.utils';
import {
cellFormatDefault,
checkForSchemaChanges,
untilSheetSelected,
} from '../../helpers/GoogleSheets.utils';
import { cellFormat, handlingExtraData, locationDefine } from './commonDescription';
export const description: SheetProperties = [
@@ -252,6 +261,12 @@ export async function execute(
}
columnNames = sheetData[headerRow];
if (nodeVersion >= 4.4) {
const schema = this.getNodeParameter('columns.schema', 0) as ResourceMapperField[];
checkForSchemaChanges(this.getNode(), columnNames, schema);
}
const newColumns = new Set<string>();
const columnsToMatchOn: string[] =

View File

@@ -9,7 +9,7 @@ export const versionDescription: INodeTypeDescription = {
name: 'googleSheets',
icon: 'file:googleSheets.svg',
group: ['input', 'output'],
version: [3, 4, 4.1, 4.2, 4.3],
version: [3, 4, 4.1, 4.2, 4.3, 4.4],
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Read, update and write data to Google Sheets',
defaults: {