fix(core): Disallow orphan executions (#7069)
Until https://github.com/n8n-io/n8n/pull/7061 we had an edge case where a manual unsaved workflow when run creates an orphan execution, i.e. a saved execution not pointing to any workflow. This execution is only ever visible to the instance owner (even if triggered by a member), and is wrongly stored as unfinished and crashed. This PR enforces that the DB disallows any such executions from making it into the DB. This is needed also for the S3 client, which will include the `workflowId` in the path-like filename. --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import type { MigrationContext, ReversibleMigration } from '@db/types';
|
||||
|
||||
export class DisallowOrphanExecutions1693554410387 implements ReversibleMigration {
|
||||
/**
|
||||
* Ensure all executions point to a workflow.
|
||||
*/
|
||||
async up({ escape, schemaBuilder: { addNotNull }, runQuery }: MigrationContext) {
|
||||
const executionEntity = escape.tableName('execution_entity');
|
||||
const workflowId = escape.columnName('workflowId');
|
||||
|
||||
await runQuery(`DELETE FROM ${executionEntity} WHERE ${workflowId} IS NULL;`);
|
||||
|
||||
await addNotNull('execution_entity', 'workflowId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reversal excludes restoring deleted rows.
|
||||
*/
|
||||
async down({ schemaBuilder: { dropNotNull } }: MigrationContext) {
|
||||
await dropNotNull('execution_entity', 'workflowId');
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ import { RemoveResetPasswordColumns1690000000030 } from '../common/1690000000030
|
||||
import { CreateWorkflowNameIndex1691088862123 } from '../common/1691088862123-CreateWorkflowNameIndex';
|
||||
import { AddMfaColumns1690000000030 } from './../common/1690000000040-AddMfaColumns';
|
||||
import { CreateWorkflowHistoryTable1692967111175 } from '../common/1692967111175-CreateWorkflowHistoryTable';
|
||||
import { DisallowOrphanExecutions1693554410387 } from '../common/1693554410387-DisallowOrphanExecutions';
|
||||
import { ExecutionSoftDelete1693491613982 } from '../common/1693491613982-ExecutionSoftDelete';
|
||||
|
||||
export const mysqlMigrations: Migration[] = [
|
||||
@@ -96,5 +97,6 @@ export const mysqlMigrations: Migration[] = [
|
||||
CreateWorkflowNameIndex1691088862123,
|
||||
AddMfaColumns1690000000030,
|
||||
CreateWorkflowHistoryTable1692967111175,
|
||||
DisallowOrphanExecutions1693554410387,
|
||||
ExecutionSoftDelete1693491613982,
|
||||
];
|
||||
|
||||
@@ -44,6 +44,7 @@ import { AddMissingPrimaryKeyOnExecutionData1690787606731 } from './169078760673
|
||||
import { CreateWorkflowNameIndex1691088862123 } from '../common/1691088862123-CreateWorkflowNameIndex';
|
||||
import { AddMfaColumns1690000000030 } from './../common/1690000000040-AddMfaColumns';
|
||||
import { CreateWorkflowHistoryTable1692967111175 } from '../common/1692967111175-CreateWorkflowHistoryTable';
|
||||
import { DisallowOrphanExecutions1693554410387 } from '../common/1693554410387-DisallowOrphanExecutions';
|
||||
import { ExecutionSoftDelete1693491613982 } from '../common/1693491613982-ExecutionSoftDelete';
|
||||
|
||||
export const postgresMigrations: Migration[] = [
|
||||
@@ -92,5 +93,6 @@ export const postgresMigrations: Migration[] = [
|
||||
CreateWorkflowNameIndex1691088862123,
|
||||
AddMfaColumns1690000000030,
|
||||
CreateWorkflowHistoryTable1692967111175,
|
||||
DisallowOrphanExecutions1693554410387,
|
||||
ExecutionSoftDelete1693491613982,
|
||||
];
|
||||
|
||||
@@ -43,6 +43,7 @@ import { RemoveResetPasswordColumns1690000000030 } from './1690000000030-RemoveR
|
||||
import { CreateWorkflowNameIndex1691088862123 } from '../common/1691088862123-CreateWorkflowNameIndex';
|
||||
import { AddMfaColumns1690000000030 } from './1690000000040-AddMfaColumns';
|
||||
import { CreateWorkflowHistoryTable1692967111175 } from '../common/1692967111175-CreateWorkflowHistoryTable';
|
||||
import { DisallowOrphanExecutions1693554410387 } from '../common/1693554410387-DisallowOrphanExecutions';
|
||||
import { ExecutionSoftDelete1693491613982 } from './1693491613982-ExecutionSoftDelete';
|
||||
|
||||
const sqliteMigrations: Migration[] = [
|
||||
@@ -90,6 +91,7 @@ const sqliteMigrations: Migration[] = [
|
||||
CreateWorkflowNameIndex1691088862123,
|
||||
AddMfaColumns1690000000030,
|
||||
CreateWorkflowHistoryTable1692967111175,
|
||||
DisallowOrphanExecutions1693554410387,
|
||||
ExecutionSoftDelete1693491613982,
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user