-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Disallow orphan executions (#7069)
Until #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>
- Loading branch information
Showing
7 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/cli/src/databases/migrations/common/1693554410387-DisallowOrphanExecutions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters