-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtable
252 lines (228 loc) · 9.17 KB
/
table
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TYPE resource_type_enum AS ENUM ('Product', 'Resource', 'Asset');
CREATE TYPE template_type_enum AS ENUM ('FDA', 'Custom');
CREATE TYPE event_type_enum AS ENUM ('EconomicEvent');
CREATE TYPE action_type_enum AS ENUM ('Cite', 'Modify', 'Produce', 'Consume', 'Transfer', 'Use', 'Load', 'Unload', 'Accept', 'Dispatch');
CREATE TYPE role_type_enum AS ENUM ('Input', 'Output');
CREATE TYPE field_class_enum AS ENUM (
'resourceSpecification',
'economicResource',
'quantity',
'hasPointInTime',
'agent',
'location',
'note',
'trackingIdentifier',
'custom',
'referenceDocumentNumber',
'referenceDocumentType'
);
CREATE TYPE field_group_class_enum AS ENUM ('ResourceSpecification', 'EconomicResource', 'Location', 'Custom', 'ReferenceDocument');
CREATE TYPE field_type_enum AS ENUM ('Text', 'Date', 'Number', 'Select');
CREATE TYPE flow_through_enum AS ENUM ('Internal', 'External');
-- Company Table
CREATE TABLE IF NOT EXISTS agents (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT NOT NULL,
note TEXT,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Products Specification Table
CREATE TABLE IF NOT EXISTS resource_specifications (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
agent_id UUID NOT NULL REFERENCES agents(id),
name TEXT NOT NULL,
note TEXT,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
resource_type resource_type_enum NOT NULL,
unit_of_measure TEXT NOT NULL
);
-- Products Table, Inventory
CREATE TABLE IF NOT EXISTS economic_resources (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
resource_specification_id UUID NOT NULL REFERENCES resource_specifications(id),
name TEXT NOT NULL,
note TEXT,
accounting_quantity INTEGER NOT NULL,
on_hand_quantity INTEGER NOT NULL,
tracking_identifier TEXT,
current_location TEXT NOT NULL,
lot TEXT,
contained_in UUID REFERENCES economic_resources(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
reference_number SERIAL
);
-- ProcessTemplates
CREATE TABLE IF NOT EXISTS map_templates (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT NOT NULL,
type template_type_enum NOT NULL
);
-- ProcessTemplates
CREATE TABLE IF NOT EXISTS recipe_templates (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
map_template_id UUID NOT NULL REFERENCES map_templates(id),
identifier TEXT NOT NULL,
name TEXT NOT NULL,
commitment action_type_enum,
fulfills UUID REFERENCES recipe_templates(id),
trigger action_type_enum,
version INTEGER NOT NULL DEFAULT 1,
overrides UUID REFERENCES recipe_templates(id),
created_by UUID REFERENCES agents(id)
);
-- ProcessWhitelistRules,
CREATE TABLE IF NOT EXISTS recipe_template_blacklists (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
map_template_id UUID NOT NULL REFERENCES map_templates(id),
recipe_template_id UUID NOT NULL REFERENCES recipe_templates(id),
recipe_template_predecesor_id UUID NOT NULL REFERENCES recipe_templates(id),
CONSTRAINT unique_process_restriction UNIQUE (recipe_template_id, recipe_template_predecesor_id)
);
-- ProcessTemplateAccess
CREATE TABLE IF NOT EXISTS recipe_templates_access (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
agent_id UUID NOT NULL REFERENCES agents(id),
recipe_template_id UUID NOT NULL REFERENCES recipe_templates(id)
);
-- ProcessFlowTemplates
CREATE TABLE IF NOT EXISTS recipe_flow_templates (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
recipe_template_id UUID NOT NULL REFERENCES recipe_templates(id),
event_type event_type_enum NOT NULL,
role_type role_type_enum NOT NULL,
action action_type_enum NOT NULL,
identifier TEXT NOT NULL,
interactions INTEGER
);
-- ProcessFlowTemplateGroupDataFields
CREATE TABLE IF NOT EXISTS recipe_flow_template_group_data_fields (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT NOT NULL,
group_class field_group_class_enum NOT NULL
);
-- ProcessFlowTemplateDataFields
CREATE TABLE IF NOT EXISTS recipe_flow_template_data_fields (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
recipe_flow_template_id UUID NOT NULL REFERENCES recipe_flow_templates(id),
group_id UUID REFERENCES recipe_flow_template_group_data_fields(id),
field_identifier TEXT NOT NULL,
field_class field_class_enum NOT NULL,
field TEXT NOT NULL,
field_type field_type_enum NOT NULL,
note TEXT,
required BOOLEAN NOT NULL,
flow_through flow_through_enum,
inherits UUID REFERENCES recipe_flow_template_data_fields(id),
accept_default BOOLEAN NOT NULL
);
-- Locations
CREATE TABLE IF NOT EXISTS locations (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
agent_id UUID NOT NULL REFERENCES agents(id),
name TEXT NOT NULL,
value TEXT NOT NULL
);
-- Counters, product lot_codes and reference_numbers
CREATE TABLE IF NOT EXISTS counters (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
agent_id UUID NOT NULL REFERENCES agents(id),
lot_code INTEGER NOT NULL DEFAULT 0,
reference_number INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Process Map
CREATE TABLE IF NOT EXISTS recipes (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
agent_id UUID NOT NULL REFERENCES agents(id),
name TEXT NOT NULL,
note TEXT,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Process Map Products
CREATE TABLE IF NOT EXISTS recipe_resources (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
recipe_id UUID NOT NULL REFERENCES recipes(id),
resource_specification_id UUID NOT NULL REFERENCES resource_specifications(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Process Map process, Process
CREATE TABLE IF NOT EXISTS recipe_processes (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
recipe_id UUID NOT NULL REFERENCES recipes(id),
recipe_template_id UUID REFERENCES recipe_templates(id),
name TEXT NOT NULL,
commitment action_type_enum,
fulfills UUID REFERENCES recipe_processes(id),
identifier TEXT NOT NULL UNIQUE,
trigger action_type_enum
);
-- Process connection relations
CREATE TABLE IF NOT EXISTS recipe_process_relations (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
recipe_process_id UUID NOT NULL REFERENCES recipe_processes(id),
output_of UUID NOT NULL REFERENCES recipe_processes(id) -- Corrected the syntax here
);
-- Process Flow, FORM
CREATE TABLE IF NOT EXISTS recipe_process_flows (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
recipe_process_id UUID NOT NULL REFERENCES recipe_processes(id),
recipe_flow_template_id UUID NOT NULL REFERENCES recipe_flow_templates(id),
event_type event_type_enum NOT NULL,
role_type role_type_enum NOT NULL,
action action_type_enum NOT NULL,
identifier TEXT NOT NULL UNIQUE
);
-- Process Flow Group Data Fields
CREATE TABLE IF NOT EXISTS recipe_process_flow_group_data_fields (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT NOT NULL,
group_class field_group_class_enum NOT NULL
);
-- Process Flow Data Fields
CREATE TABLE IF NOT EXISTS recipe_process_flow_data_fields (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
recipe_process_flow_id UUID NOT NULL REFERENCES recipe_process_flows(id),
recipe_flow_template_data_field_id UUID REFERENCES recipe_flow_template_data_fields(id),
group_id UUID REFERENCES recipe_process_flow_group_data_fields(id),
field_identifier TEXT NOT NULL,
field_class field_class_enum NOT NULL,
field TEXT NOT NULL,
field_type field_type_enum NOT NULL,
note TEXT,
required BOOLEAN NOT NULL,
default_value TEXT,
flow_through flow_through_enum,
inherits UUID REFERENCES recipe_process_flow_data_fields(id)
);
-- Process Executions
CREATE TABLE IF NOT EXISTS process_executions (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
process_flow_id UUID NOT NULL REFERENCES recipe_process_flows(id),
action action_type_enum NOT NULL,
role_type role_type_enum NOT NULL,
resource_specification UUID REFERENCES resource_specifications(id),
resource_reference_number INTEGER,
resource_lot_number INTEGER,
resource_quantity INTEGER,
to_resource_specification UUID REFERENCES resource_specifications(id),
to_resource_reference_number INTEGER,
to_resource_lot_number INTEGER,
provider_agent UUID NOT NULL REFERENCES agents(id),
receiver_agent UUID NOT NULL REFERENCES agents(id),
at_location UUID REFERENCES locations(id),
to_location UUID REFERENCES locations(id),
has_point_in_time TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
corrects UUID REFERENCES process_executions(id),
note TEXT
);
-- Process Execution Custom Values
CREATE TABLE IF NOT EXISTS process_execution_custom_values (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
process_execution_id UUID NOT NULL REFERENCES process_executions(id),
field_id UUID NOT NULL REFERENCES recipe_process_flow_data_fields(id),
field_value TEXT NOT NULL,
corrects UUID REFERENCES process_execution_custom_values(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);