mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
fix(core): Fix named parameter resolution in migrations (#7688)
Fixes #7628
This commit is contained in:
parent
91c3ea87fe
commit
4441ed5116
|
@ -20,11 +20,10 @@ export class UniqueWorkflowNames1620821879465 implements ReversibleMigration {
|
|||
await Promise.all(
|
||||
duplicates.map(async (workflow, index) => {
|
||||
if (index === 0) return;
|
||||
return runQuery(
|
||||
`UPDATE ${tableName} SET name = :name WHERE id = :id`,
|
||||
{ name: `${workflow.name} ${index + 1}` },
|
||||
{ id: workflow.id },
|
||||
);
|
||||
return runQuery(`UPDATE ${tableName} SET name = :name WHERE id = :id`, {
|
||||
name: `${workflow.name} ${index + 1}`,
|
||||
id: workflow.id,
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -42,11 +42,10 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati
|
|||
}
|
||||
});
|
||||
if (credentialsUpdated) {
|
||||
await runQuery(
|
||||
`UPDATE ${workflowsTable} SET nodes = :nodes WHERE id = :id`,
|
||||
{ nodes: JSON.stringify(nodes) },
|
||||
{ id: workflow.id },
|
||||
);
|
||||
await runQuery(`UPDATE ${workflowsTable} SET nodes = :nodes WHERE id = :id`, {
|
||||
nodes: JSON.stringify(nodes),
|
||||
id: workflow.id,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -79,8 +78,7 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati
|
|||
await runQuery(
|
||||
`UPDATE ${executionsTable}
|
||||
SET ${escape.columnName('workflowData')} = :data WHERE id = :id`,
|
||||
{ data: JSON.stringify(workflowData) },
|
||||
{ id: execution.id },
|
||||
{ data: JSON.stringify(workflowData), id: execution.id },
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -114,8 +112,7 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati
|
|||
await runQuery(
|
||||
`UPDATE ${executionsTable}
|
||||
SET ${escape.columnName('workflowData')} = :data WHERE id = :id`,
|
||||
{ data: JSON.stringify(workflowData) },
|
||||
{ id: execution.id },
|
||||
{ data: JSON.stringify(workflowData), id: execution.id },
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -160,11 +157,10 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati
|
|||
}
|
||||
});
|
||||
if (credentialsUpdated) {
|
||||
await runQuery(
|
||||
`UPDATE ${workflowsTable} SET nodes = :nodes WHERE id = :id`,
|
||||
{ nodes: JSON.stringify(nodes) },
|
||||
{ id: workflow.id },
|
||||
);
|
||||
await runQuery(`UPDATE ${workflowsTable} SET nodes = :nodes WHERE id = :id`, {
|
||||
nodes: JSON.stringify(nodes),
|
||||
id: workflow.id,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -206,8 +202,7 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati
|
|||
await runQuery(
|
||||
`UPDATE ${executionsTable}
|
||||
SET ${escape.columnName('workflowData')} = :data WHERE id = :id`,
|
||||
{ data: JSON.stringify(workflowData) },
|
||||
{ id: execution.id },
|
||||
{ data: JSON.stringify(workflowData), id: execution.id },
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -249,8 +244,7 @@ export class UpdateWorkflowCredentials1630330987096 implements ReversibleMigrati
|
|||
await runQuery(
|
||||
`UPDATE ${executionsTable}
|
||||
SET ${escape.columnName('workflowData')} = :data WHERE id = :id`,
|
||||
{ data: JSON.stringify(workflowData) },
|
||||
{ id: execution.id },
|
||||
{ data: JSON.stringify(workflowData), id: execution.id },
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -18,11 +18,10 @@ export class AddNodeIds1658930531669 implements ReversibleMigration {
|
|||
}
|
||||
});
|
||||
|
||||
await runQuery(
|
||||
`UPDATE ${tableName} SET nodes = :nodes WHERE id = :id`,
|
||||
{ nodes: JSON.stringify(nodes) },
|
||||
{ id: workflow.id },
|
||||
);
|
||||
await runQuery(`UPDATE ${tableName} SET nodes = :nodes WHERE id = :id`, {
|
||||
nodes: JSON.stringify(nodes),
|
||||
id: workflow.id,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -33,11 +32,10 @@ export class AddNodeIds1658930531669 implements ReversibleMigration {
|
|||
await runInBatches<Workflow>(workflowsQuery, async (workflows) => {
|
||||
workflows.forEach(async (workflow) => {
|
||||
const nodes = parseJson(workflow.nodes).map(({ id, ...rest }) => rest);
|
||||
await runQuery(
|
||||
`UPDATE ${tableName} SET nodes = :nodes WHERE id = :id`,
|
||||
{ nodes: JSON.stringify(nodes) },
|
||||
{ id: workflow.id },
|
||||
);
|
||||
await runQuery(`UPDATE ${tableName} SET nodes = :nodes WHERE id = :id`, {
|
||||
nodes: JSON.stringify(nodes),
|
||||
id: workflow.id,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -12,11 +12,10 @@ export class AddWorkflowVersionIdColumn1669739707124 implements ReversibleMigrat
|
|||
|
||||
const workflowIds: Workflow[] = await runQuery(`SELECT id FROM ${tableName}`);
|
||||
for (const { id } of workflowIds) {
|
||||
await runQuery(
|
||||
`UPDATE ${tableName} SET ${columnName} = :versionId WHERE id = :id`,
|
||||
{ versionId: uuidv4() },
|
||||
{ id },
|
||||
);
|
||||
await runQuery(`UPDATE ${tableName} SET ${columnName} = :versionId WHERE id = :id`, {
|
||||
versionId: uuidv4(),
|
||||
id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,11 +47,10 @@ export class PurgeInvalidWorkflowConnections1675940580449 implements Irreversibl
|
|||
});
|
||||
|
||||
// Update database with new connections
|
||||
return runQuery(
|
||||
`UPDATE ${workflowsTable} SET connections = :connections WHERE id = :id`,
|
||||
{ connections: JSON.stringify(connections) },
|
||||
{ id: workflow.id },
|
||||
);
|
||||
return runQuery(`UPDATE ${workflowsTable} SET connections = :connections WHERE id = :id`, {
|
||||
connections: JSON.stringify(connections),
|
||||
id: workflow.id,
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -22,11 +22,7 @@ export interface MigrationContext {
|
|||
tableName(name: string): string;
|
||||
indexName(name: string): string;
|
||||
};
|
||||
runQuery<T>(
|
||||
sql: string,
|
||||
unsafeParameters?: ObjectLiteral,
|
||||
nativeParameters?: ObjectLiteral,
|
||||
): Promise<T>;
|
||||
runQuery<T>(sql: string, namedParameters?: ObjectLiteral): Promise<T>;
|
||||
runInBatches<T>(
|
||||
query: string,
|
||||
operation: (results: T[]) => Promise<void>,
|
||||
|
|
|
@ -110,16 +110,12 @@ const createContext = (queryRunner: QueryRunner, migration: Migration): Migratio
|
|||
tableName: (name) => queryRunner.connection.driver.escape(`${tablePrefix}${name}`),
|
||||
indexName: (name) => queryRunner.connection.driver.escape(`IDX_${tablePrefix}${name}`),
|
||||
},
|
||||
runQuery: async <T>(
|
||||
sql: string,
|
||||
unsafeParameters?: ObjectLiteral,
|
||||
safeParameters?: ObjectLiteral,
|
||||
) => {
|
||||
if (unsafeParameters) {
|
||||
runQuery: async <T>(sql: string, namedParameters?: ObjectLiteral) => {
|
||||
if (namedParameters) {
|
||||
const [query, parameters] = queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
sql,
|
||||
unsafeParameters,
|
||||
safeParameters ?? {},
|
||||
namedParameters,
|
||||
{},
|
||||
);
|
||||
return queryRunner.query(query, parameters) as Promise<T>;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue