mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
feat(core, editor): Support pairedItem for pinned data (#3843)
* 📘 Adjust interface * ⚡ Adjust pindata in state store * ✨ Add utils * ⚡ Replace utils calls * ⚡ Adjust pindata intake and display * 🔥 Remove excess BE fixes * 📝 Update comment * 🧪 Adjust tests * 🔥 Remove unneeded helper * 🚚 Improve naming * 🧹 Clean up `ormconfig.ts` * 📘 Add types and type guards * ⚡ Improve serializer for sqlite * ✨ Create migration utils * ⚡ Set up sqlite serializer * 🗃️ Write sqlite migration * 🗃️ Write MySQL migration * 🗃️ Write Postgres migration * ⚡ Add imports and exports to barrels * 🚚 Rename `runChunked` to `runInBatches` * ⚡ Improve migration loggers * ♻️ Address feedback * 🚚 Improve naming
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import * as config from '../../../../config';
|
||||
import { logMigrationEnd, logMigrationStart } from '../../utils/migrationHelpers';
|
||||
import { runChunked } from '../../utils/migrationHelpers';
|
||||
import { runInBatches } from '../../utils/migrationHelpers';
|
||||
|
||||
// replacing the credentials in workflows and execution
|
||||
// `nodeType: name` changes to `nodeType: { id, name }`
|
||||
@@ -25,7 +25,7 @@ export class UpdateWorkflowCredentials1630330987096 implements MigrationInterfac
|
||||
`;
|
||||
|
||||
// @ts-ignore
|
||||
await runChunked(queryRunner, workflowsQuery, (workflows) => {
|
||||
await runInBatches(queryRunner, workflowsQuery, (workflows) => {
|
||||
workflows.forEach(async (workflow) => {
|
||||
const nodes = JSON.parse(workflow.nodes);
|
||||
let credentialsUpdated = false;
|
||||
@@ -68,7 +68,7 @@ export class UpdateWorkflowCredentials1630330987096 implements MigrationInterfac
|
||||
WHERE "waitTill" IS NOT NULL AND finished = 0
|
||||
`;
|
||||
// @ts-ignore
|
||||
await runChunked(queryRunner, waitingExecutionsQuery, (waitingExecutions) => {
|
||||
await runInBatches(queryRunner, waitingExecutionsQuery, (waitingExecutions) => {
|
||||
waitingExecutions.forEach(async (execution) => {
|
||||
const data = JSON.parse(execution.workflowData);
|
||||
let credentialsUpdated = false;
|
||||
@@ -164,7 +164,7 @@ export class UpdateWorkflowCredentials1630330987096 implements MigrationInterfac
|
||||
`;
|
||||
|
||||
// @ts-ignore
|
||||
await runChunked(queryRunner, workflowsQuery, (workflows) => {
|
||||
await runInBatches(queryRunner, workflowsQuery, (workflows) => {
|
||||
// @ts-ignore
|
||||
workflows.forEach(async (workflow) => {
|
||||
const nodes = JSON.parse(workflow.nodes);
|
||||
@@ -214,7 +214,7 @@ export class UpdateWorkflowCredentials1630330987096 implements MigrationInterfac
|
||||
`;
|
||||
|
||||
// @ts-ignore
|
||||
await runChunked(queryRunner, waitingExecutionsQuery, (waitingExecutions) => {
|
||||
await runInBatches(queryRunner, waitingExecutionsQuery, (waitingExecutions) => {
|
||||
// @ts-ignore
|
||||
waitingExecutions.forEach(async (execution) => {
|
||||
const data = JSON.parse(execution.workflowData);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { INode } from 'n8n-workflow';
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import * as config from '../../../../config';
|
||||
import { logMigrationEnd, logMigrationStart } from '../../utils/migrationHelpers';
|
||||
import { runChunked } from '../../utils/migrationHelpers';
|
||||
import { runInBatches } from '../../utils/migrationHelpers';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
// add node ids in workflow objects
|
||||
@@ -21,7 +21,7 @@ export class AddNodeIds1658930531669 implements MigrationInterface {
|
||||
`;
|
||||
|
||||
// @ts-ignore
|
||||
await runChunked(queryRunner, workflowsQuery, (workflows) => {
|
||||
await runInBatches(queryRunner, workflowsQuery, (workflows) => {
|
||||
workflows.forEach(async (workflow) => {
|
||||
const nodes = JSON.parse(workflow.nodes);
|
||||
nodes.forEach((node: INode) => {
|
||||
@@ -30,16 +30,15 @@ export class AddNodeIds1658930531669 implements MigrationInterface {
|
||||
}
|
||||
});
|
||||
|
||||
const [updateQuery, updateParams] =
|
||||
queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
`
|
||||
const [updateQuery, updateParams] = queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
`
|
||||
UPDATE "${tablePrefix}workflow_entity"
|
||||
SET nodes = :nodes
|
||||
WHERE id = '${workflow.id}'
|
||||
`,
|
||||
{ nodes: JSON.stringify(nodes) },
|
||||
{},
|
||||
);
|
||||
{ nodes: JSON.stringify(nodes) },
|
||||
{},
|
||||
);
|
||||
|
||||
queryRunner.query(updateQuery, updateParams);
|
||||
});
|
||||
@@ -48,7 +47,6 @@ export class AddNodeIds1658930531669 implements MigrationInterface {
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const tablePrefix = config.getEnv('database.tablePrefix');
|
||||
|
||||
@@ -58,22 +56,21 @@ export class AddNodeIds1658930531669 implements MigrationInterface {
|
||||
`;
|
||||
|
||||
// @ts-ignore
|
||||
await runChunked(queryRunner, workflowsQuery, (workflows) => {
|
||||
await runInBatches(queryRunner, workflowsQuery, (workflows) => {
|
||||
workflows.forEach(async (workflow) => {
|
||||
const nodes = JSON.parse(workflow.nodes);
|
||||
// @ts-ignore
|
||||
nodes.forEach((node) => delete node.id );
|
||||
nodes.forEach((node) => delete node.id);
|
||||
|
||||
const [updateQuery, updateParams] =
|
||||
queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
`
|
||||
const [updateQuery, updateParams] = queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
`
|
||||
UPDATE "${tablePrefix}workflow_entity"
|
||||
SET nodes = :nodes
|
||||
WHERE id = '${workflow.id}'
|
||||
`,
|
||||
{ nodes: JSON.stringify(nodes) },
|
||||
{},
|
||||
);
|
||||
{ nodes: JSON.stringify(nodes) },
|
||||
{},
|
||||
);
|
||||
|
||||
queryRunner.query(updateQuery, updateParams);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import {
|
||||
logMigrationStart,
|
||||
logMigrationEnd,
|
||||
runInBatches,
|
||||
getTablePrefix,
|
||||
escapeQuery,
|
||||
} from '../../utils/migrationHelpers';
|
||||
import type { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { isJsonKeyObject, PinData } from '../../utils/migrations.types';
|
||||
|
||||
/**
|
||||
* Convert TEXT-type `pinData` column in `workflow_entity` table from
|
||||
* `{ [nodeName: string]: IDataObject[] }` to `{ [nodeName: string]: INodeExecutionData[] }`
|
||||
*/
|
||||
export class AddJsonKeyPinData1659888469333 implements MigrationInterface {
|
||||
name = 'AddJsonKeyPinData1659888469333';
|
||||
|
||||
async up(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
|
||||
const workflowTable = `${getTablePrefix()}workflow_entity`;
|
||||
|
||||
const PINDATA_SELECT_QUERY = `
|
||||
SELECT id, pinData
|
||||
FROM "${workflowTable}"
|
||||
WHERE pinData IS NOT NULL;
|
||||
`;
|
||||
|
||||
const PINDATA_UPDATE_STATEMENT = `
|
||||
UPDATE "${workflowTable}"
|
||||
SET "pinData" = :pinData
|
||||
WHERE id = :id;
|
||||
`;
|
||||
|
||||
await runInBatches(
|
||||
queryRunner,
|
||||
PINDATA_SELECT_QUERY,
|
||||
addJsonKeyToPinDataColumn(queryRunner, PINDATA_UPDATE_STATEMENT),
|
||||
);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down() {
|
||||
// irreversible migration
|
||||
}
|
||||
}
|
||||
|
||||
export const addJsonKeyToPinDataColumn =
|
||||
(queryRunner: QueryRunner, updateStatement: string) =>
|
||||
async (fetchedWorkflows: PinData.FetchedWorkflow[]) => {
|
||||
makeUpdateParams(fetchedWorkflows).forEach((param) => {
|
||||
const params = {
|
||||
pinData: param.pinData,
|
||||
id: param.id,
|
||||
};
|
||||
|
||||
const [escapedStatement, escapedParams] = escapeQuery(queryRunner, updateStatement, params);
|
||||
|
||||
queryRunner.query(escapedStatement, escapedParams);
|
||||
});
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
const newPinDataPerWorkflow = Object.keys(pinDataPerWorkflow).reduce<PinData.New>(
|
||||
(newPinDataPerWorkflow, nodeName) => {
|
||||
const pinDataPerNode = pinDataPerWorkflow[nodeName];
|
||||
|
||||
if (pinDataPerNode.every((item) => item.json)) return newPinDataPerWorkflow;
|
||||
|
||||
newPinDataPerWorkflow[nodeName] = pinDataPerNode.map((item) =>
|
||||
isJsonKeyObject(item) ? item : { json: item },
|
||||
);
|
||||
|
||||
return newPinDataPerWorkflow;
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
if (Object.keys(newPinDataPerWorkflow).length > 0) {
|
||||
updateParams.push({ id, pinData: JSON.stringify(newPinDataPerWorkflow) });
|
||||
}
|
||||
|
||||
return updateParams;
|
||||
},
|
||||
[],
|
||||
);
|
||||
}
|
||||
@@ -11,10 +11,11 @@ import { AddExecutionEntityIndexes1644421939510 } from './1644421939510-AddExecu
|
||||
import { CreateUserManagement1646992772331 } from './1646992772331-CreateUserManagement';
|
||||
import { LowerCaseUserEmail1648740597343 } from './1648740597343-LowerCaseUserEmail';
|
||||
import { AddUserSettings1652367743993 } from './1652367743993-AddUserSettings';
|
||||
import { CommunityNodes1652254514001 } from './1652254514001-CommunityNodes'
|
||||
import { CommunityNodes1652254514001 } from './1652254514001-CommunityNodes';
|
||||
import { AddAPIKeyColumn1652905585850 } from './1652905585850-AddAPIKeyColumn';
|
||||
import { IntroducePinData1654089251344 } from './1654089251344-IntroducePinData';
|
||||
import { AddNodeIds1658930531669 } from './1658930531669-AddNodeIds';
|
||||
import { AddJsonKeyPinData1659888469333 } from './1659888469333-AddJsonKeyPinData';
|
||||
|
||||
const sqliteMigrations = [
|
||||
InitialMigration1588102412422,
|
||||
@@ -34,6 +35,7 @@ const sqliteMigrations = [
|
||||
AddAPIKeyColumn1652905585850,
|
||||
IntroducePinData1654089251344,
|
||||
AddNodeIds1658930531669,
|
||||
AddJsonKeyPinData1659888469333,
|
||||
];
|
||||
|
||||
export { sqliteMigrations };
|
||||
|
||||
Reference in New Issue
Block a user