|
1
|
import { TransactionState } from "@medusajs/framework/orchestration" |
|
2
|
import { model } from "@medusajs/framework/utils" |
|
3
|
|
|
4
|
export const WorkflowExecution = model |
|
5
|
.define("workflow_execution", { |
|
6
|
id: model.id({ prefix: "wf_exec" }), |
|
7
|
workflow_id: model.text().primaryKey(), |
|
8
|
transaction_id: model.text().primaryKey(), |
|
9
|
run_id: model.text().primaryKey(), |
|
10
|
execution: model.json().nullable(), |
|
11
|
context: model.json().nullable(), |
|
12
|
state: model.enum(TransactionState), |
|
13
|
retention_time: model.number().nullable(), |
|
14
|
}) |
|
15
|
.indexes([ |
|
16
|
{ |
|
17
|
on: ["id"], |
|
18
|
where: "deleted_at IS NULL", |
|
19
|
}, |
|
20
|
{ |
|
21
|
on: ["workflow_id"], |
|
22
|
where: "deleted_at IS NULL", |
|
23
|
}, |
|
24
|
{ |
|
25
|
on: ["transaction_id"], |
|
26
|
where: "deleted_at IS NULL", |
|
27
|
}, |
|
28
|
{ |
|
29
|
on: ["workflow_id", "transaction_id", "run_id"], |
|
30
|
unique: true, |
|
31
|
where: "deleted_at IS NULL", |
|
32
|
}, |
|
33
|
{ |
|
34
|
on: ["state"], |
|
35
|
where: "deleted_at IS NULL", |
|
36
|
}, |
|
37
|
{ |
|
38
|
on: ["run_id"], |
|
39
|
where: "deleted_at IS NULL", |
|
40
|
}, |
|
41
|
{ |
|
42
|
on: ["workflow_id", "transaction_id"], |
|
43
|
where: "deleted_at IS NULL", |
|
44
|
}, |
|
45
|
{ |
|
46
|
on: ["state", "updated_at"], |
|
47
|
where: "deleted_at IS NULL", |
|
48
|
}, |
|
49
|
{ |
|
50
|
on: ["retention_time", "updated_at", "state"], |
|
51
|
where: "deleted_at IS NULL AND retention_time IS NOT NULL", |
|
52
|
}, |
|
53
|
{ |
|
54
|
on: ["updated_at", "retention_time"], |
|
55
|
where: |
|
56
|
"deleted_at IS NULL AND retention_time IS NOT NULL AND state IN ('done', 'failed', 'reverted')", |
|
57
|
}, |
|
58
|
]) |