fix(workflows): Postgres-safe id capture on workflow inserts
On Postgres, knex .insert() without .returning() resolves to [], so ins[0]
was undefined → the child workflow_nodes inserts hit a NOT NULL violation and
the whole transaction rolled back. Result on PG: migration + tables present
but zero rows — the seeded dunning flow never persisted, and the 'New
workflow' button would 500. SQLite returns the row id, so the test harness
masked it.
Add .returning('id') and normalise the {id} (pg) vs bare-id (sqlite) shapes
(same pattern as the crmDb harness) in both the built-in seed and the admin
create route. Tests stay green on SQLite (17).
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user