JEISA-WEBAPP/pocketbase/pb_migrations/1786200006_created_workflow_runs.js
Dave c272526d67 feat(automation): add PO-to-invoice pipeline
- 6 new PocketBase migrations: customer_pos, customer_po_lines, invoices,
  invoice_items, email_inbox, workflow_runs
- n8N workflow JSON: 01-customer-po-to-parsed.json + 02-parsed-po-to-invoice.json
- MCP server config (.cursor/mcp.json + .mcp.json) for AI agent PB access
- .env.example template with all required credentials documented
- n8n/README.md with deployment, testing, and customization notes
2026-09-06 23:40:33 +02:00

155 lines
No EOL
4.1 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
// =========================================================================
// workflow_runs — history of every n8N execution
// =========================================================================
//
// n8N POSTs to a PocketBase endpoint once per execution. We store the run id,
// workflow name, status, inputs/outputs (json), and any error. This lets us
// see in the dashboard what happened last time, even when n8N's UI isn't open.
// =========================================================================
migrate((app) => {
const cpoCol = app.findCollectionByNameOrId("customer_pos");
const invoicesCol = app.findCollectionByNameOrId("invoices");
const collection = new Collection({
"createRule": "@request.auth.id != ''",
"deleteRule": "@request.auth.id != ''",
"listRule": "@request.auth.id != ''",
"name": "workflow_runs",
"system": false,
"type": "base",
"updateRule": "@request.auth.id != ''",
"viewRule": "@request.auth.id != ''",
"fields": [
{
"autogeneratePattern": "",
"hidden": false,
"id": "txt_wfr_n8n_id",
"max": 100,
"min": 0,
"name": "n8n_execution_id",
"pattern": "",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "text"
},
{
"autogeneratePattern": "",
"hidden": false,
"id": "txt_wfr_workflow",
"max": 200,
"min": 0,
"name": "workflow_name",
"pattern": "",
"presentable": true,
"primaryKey": false,
"required": false,
"system": false,
"type": "text"
},
{
"hidden": false,
"id": "sel_wfr_status",
"maxSelect": 1,
"name": "status",
"presentable": true,
"required": false,
"system": false,
"type": "select",
"values": ["running", "success", "failed", "cancelled"]
},
{
"hidden": false,
"id": "dt_wfr_started",
"max": "",
"min": "",
"name": "started_at",
"presentable": false,
"required": false,
"system": false,
"type": "date"
},
{
"hidden": false,
"id": "dt_wfr_finished",
"max": "",
"min": "",
"name": "finished_at",
"presentable": false,
"required": false,
"system": false,
"type": "date"
},
{
"hidden": false,
"id": "json_wfr_input",
"maxSize": 200000,
"name": "input_json",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json_wfr_output",
"maxSize": 500000,
"name": "output_json",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"autogeneratePattern": "",
"hidden": false,
"id": "txt_wfr_error",
"max": 0,
"min": 0,
"name": "error_message",
"pattern": "",
"presentable": false,
"primaryKey": false,
"required": false,
"system": false,
"type": "text"
},
{
"cascadeDelete": false,
"collectionId": cpoCol.id,
"hidden": false,
"id": "rel_wfr_cpo",
"maxSelect": 1,
"minSelect": 0,
"name": "related_customer_po",
"presentable": false,
"required": false,
"system": false,
"type": "relation"
},
{
"cascadeDelete": false,
"collectionId": invoicesCol.id,
"hidden": false,
"id": "rel_wfr_invoice",
"maxSelect": 1,
"minSelect": 0,
"name": "related_invoice",
"presentable": false,
"required": false,
"system": false,
"type": "relation"
}
],
"indexes": []
});
return app.save(collection);
}, (app) => {
const collection = app.findCollectionByNameOrId("workflow_runs");
return app.delete(collection);
})