Skip to content

Commit 60cd62c

Browse files
authored
fix(core): Handle null workflowId's on workflow_statistics table at migration (n8n-io#24800)
1 parent 2f370f4 commit 60cd62c

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/@n8n/db/src/migrations/sqlite/1767018516000-ChangeWorkflowStatisticsFKToNoAction.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class ChangeWorkflowStatisticsFKToNoAction1767018516000 implements Revers
1212
transaction = false as const; // Disable FK checks for table recreation
1313

1414
async up({ queryRunner, tablePrefix }: MigrationContext) {
15-
// Create new table with id primary key, workflowName column, and no foreign key constraint
15+
// Create new table with id primary key, non nullable workflowId, workflowName column, and no foreign key constraint
1616
await queryRunner.query(`
1717
CREATE TABLE "${tablePrefix}TMP_workflow_statistics" (
1818
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -25,12 +25,14 @@ export class ChangeWorkflowStatisticsFKToNoAction1767018516000 implements Revers
2525
)
2626
`);
2727

28-
// Copy data from old table and populate workflowName from workflow_entity
28+
// Copy data from old table and populate workflowName from workflow_entity.
29+
// Rows with null workflowId are skipped, they shouldn't exist in the table anyway.
2930
await queryRunner.query(`
3031
INSERT INTO "${tablePrefix}TMP_workflow_statistics" ("count", "latestEvent", "name", "workflowId", "workflowName", "rootCount")
3132
SELECT ws."count", ws."latestEvent", ws."name", ws."workflowId", we."name", ws."rootCount"
3233
FROM "${tablePrefix}workflow_statistics" ws
3334
LEFT JOIN "${tablePrefix}workflow_entity" we ON ws."workflowId" = we."id"
35+
WHERE ws."workflowId" IS NOT NULL
3436
`);
3537

3638
// Drop old table

0 commit comments

Comments
 (0)