diff --git a/backend/src/routes/adminWorkflows.js b/backend/src/routes/adminWorkflows.js index 4392fdba..325af114 100644 --- a/backend/src/routes/adminWorkflows.js +++ b/backend/src/routes/adminWorkflows.js @@ -131,8 +131,11 @@ router.post('/', requirePermission('workflows.manage'), async (req, res, next) = name: b.name, description: b.description || null, enabled: !!b.enabled, version: 1, trigger_type: b.trigger_type, trigger_config: b.trigger_config ? JSON.stringify(b.trigger_config) : null, created_by: req.admin?.id || null, - }); - const newId = ins[0]; + }).returning('id'); + // Postgres returns [] without an explicit returning clause, so ins[0] + // would be undefined → the child node inserts would violate NOT NULL. + // Normalise the {id} (pg) vs bare id (sqlite) shapes. + const newId = ins[0]?.id ?? ins[0]; await writeGraph(trx, newId, 1, b.nodes, b.edges); return newId; }); diff --git a/backend/src/services/_workflowSeedBoot.js b/backend/src/services/_workflowSeedBoot.js index 6601c607..a6a70cc9 100644 --- a/backend/src/services/_workflowSeedBoot.js +++ b/backend/src/services/_workflowSeedBoot.js @@ -127,8 +127,12 @@ async function seedBuiltinWorkflowsAtBoot(db, logger) { trigger_config: JSON.stringify({ seedVersion: SEED_VERSION }), is_builtin: true, builtin_key: DUNNING_KEY, - }); - await writeGraph(trx, ins[0], 1, nodes, edges); + }).returning('id'); + // Postgres returns [] without `.returning`, so ins[0] would be undefined + // and the child node inserts would roll back on NOT NULL. Normalise the + // {id} (pg) vs bare-id (sqlite) shapes. + const workflowId = ins[0]?.id ?? ins[0]; + await writeGraph(trx, workflowId, 1, nodes, edges); }); booted = true;