-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconstructive-compute--0.0.1.sql
More file actions
2647 lines (2085 loc) · 116 KB
/
Copy pathconstructive-compute--0.0.1.sql
File metadata and controls
2647 lines (2085 loc) · 116 KB
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\echo Use "CREATE EXTENSION constructive-compute" to load this file. \quit
CREATE SCHEMA constructive_compute_private;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_private
GRANT ALL ON FUNCTIONS TO administrator;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_private
GRANT ALL ON FUNCTIONS TO anonymous;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_private
GRANT ALL ON FUNCTIONS TO authenticated;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_private
GRANT USAGE ON SEQUENCES TO administrator;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_private
GRANT USAGE ON SEQUENCES TO authenticated;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_private
GRANT ALL ON TABLES TO administrator;
CREATE SCHEMA constructive_compute_public;
CREATE TABLE constructive_compute_public.platform_function_graphs ();
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_public
GRANT ALL ON FUNCTIONS TO administrator;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_public
GRANT ALL ON FUNCTIONS TO anonymous;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_public
GRANT ALL ON FUNCTIONS TO authenticated;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_public
GRANT USAGE ON SEQUENCES TO administrator;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_public
GRANT USAGE ON SEQUENCES TO authenticated;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_public
GRANT ALL ON TABLES TO administrator;
ALTER DEFAULT PRIVILEGES IN SCHEMA constructive_compute_public
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO authenticated;
CREATE TABLE constructive_compute_public.platform_function_graph_execution_outputs (
created_at timestamptz NOT NULL DEFAULT now()
) PARTITION BY RANGE (created_at);
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
DISABLE ROW LEVEL SECURITY;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
DISABLE ROW LEVEL SECURITY;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_execution_outputs.created_at IS 'Timestamp of output creation';
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ADD COLUMN data jsonb;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ALTER COLUMN data SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ALTER COLUMN data SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ADD COLUMN database_id uuid;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ALTER COLUMN database_id SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ALTER COLUMN database_id SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ADD COLUMN hash bytea;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ALTER COLUMN hash SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ALTER COLUMN hash SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ADD COLUMN id uuid;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ALTER COLUMN id SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ALTER COLUMN id SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ALTER COLUMN id SET DEFAULT uuidv7();
ALTER TABLE constructive_compute_public.platform_function_graph_execution_outputs
ADD CONSTRAINT platform_function_graph_execution_outputs_pkey PRIMARY KEY (created_at, id);
CREATE UNIQUE INDEX idx_platform_function_graph_execution_outputs_unique_hash ON constructive_compute_public.platform_function_graph_execution_outputs (database_id, hash, created_at);
CREATE TABLE constructive_compute_public.platform_function_graph_executions (
started_at timestamptz NOT NULL DEFAULT now()
) PARTITION BY RANGE (started_at);
ALTER TABLE constructive_compute_public.platform_function_graph_executions
DISABLE ROW LEVEL SECURITY;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
DISABLE ROW LEVEL SECURITY;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN completed_at timestamptz;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.completed_at IS 'Execution completion timestamp';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN current_wave int;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN current_wave SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN current_wave SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN current_wave SET DEFAULT 0;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN database_id uuid;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN database_id SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN database_id SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN definitions_commit_id uuid;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.definitions_commit_id IS 'Pinned definitions store commit for deterministic evaluation';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN entity_id uuid;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.entity_id IS 'Entity context (org/team) for scoped billing';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN error_code text;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.error_code IS 'Machine-readable error code when status = failed';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN error_message text;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.error_message IS 'Human-readable error description when status = failed';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN execution_plan jsonb;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.execution_plan IS 'Pre-computed topological sort as array of wave objects';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN graph_id uuid;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN graph_id SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN graph_id SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN id uuid;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN id SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN id SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN id SET DEFAULT uuidv7();
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN input_payload jsonb;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.input_payload IS 'Initial inputs provided at invocation time';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN invocation_id uuid;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.invocation_id IS 'Parent function_invocations row (for metering)';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN max_pending_jobs int;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN max_pending_jobs SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN max_pending_jobs SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN max_pending_jobs SET DEFAULT 50;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN max_ticks int;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN max_ticks SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN max_ticks SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN max_ticks SET DEFAULT 100;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN node_outputs jsonb;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN node_outputs SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN node_outputs SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN node_outputs SET DEFAULT '{}'::jsonb;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN output_node text;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN output_node SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN output_node SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN output_payload jsonb;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.output_payload IS 'Final result extracted from terminal output node';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN output_port text;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN output_port SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN output_port SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN output_port SET DEFAULT 'value';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN parent_execution_id uuid;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.parent_execution_id IS 'Parent execution when this is a sub-execution';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN parent_node_name text;
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.parent_node_name IS 'Node name in parent execution that spawned this sub-execution';
COMMENT ON COLUMN constructive_compute_public.platform_function_graph_executions.started_at IS 'Execution start timestamp';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN status text;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN status SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN status SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN status SET DEFAULT 'pending';
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD CONSTRAINT platform_function_graph_executions_status_chk
CHECK (status IN ('pending', 'running', 'completed', 'failed', 'cancelled'));
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN tick_count int;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN tick_count SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN tick_count SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN tick_count SET DEFAULT 0;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD COLUMN timeout_at timestamptz;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN timeout_at SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN timeout_at SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ALTER COLUMN timeout_at SET DEFAULT now() + '5 minutes'::interval;
ALTER TABLE constructive_compute_public.platform_function_graph_executions
ADD CONSTRAINT platform_function_graph_executions_pkey PRIMARY KEY (started_at, id);
CREATE TABLE constructive_compute_public.org_function_execution_logs (
created_at timestamptz NOT NULL DEFAULT now()
) PARTITION BY RANGE (created_at);
ALTER TABLE constructive_compute_public.org_function_execution_logs
DISABLE ROW LEVEL SECURITY;
COMMENT ON TABLE constructive_compute_public.org_function_execution_logs IS 'Function execution logs — structured console output per invocation';
ALTER TABLE constructive_compute_public.org_function_execution_logs
ADD COLUMN actor_id uuid;
COMMENT ON COLUMN constructive_compute_public.org_function_execution_logs.actor_id IS 'User who triggered the execution (NULL for system/cron)';
COMMENT ON COLUMN constructive_compute_public.org_function_execution_logs.created_at IS 'Log entry timestamp (partition key)';
ALTER TABLE constructive_compute_public.org_function_execution_logs
ADD COLUMN id uuid;
ALTER TABLE constructive_compute_public.org_function_execution_logs
ALTER COLUMN id SET NOT NULL;
ALTER TABLE constructive_compute_public.org_function_execution_logs
ALTER COLUMN id SET DEFAULT uuidv7();
COMMENT ON COLUMN constructive_compute_public.org_function_execution_logs.id IS 'Unique log entry identifier';
ALTER TABLE constructive_compute_public.org_function_execution_logs
ADD COLUMN invocation_id uuid;
COMMENT ON COLUMN constructive_compute_public.org_function_execution_logs.invocation_id IS 'Invocation this log entry belongs to (NULL for standalone job logs)';
ALTER TABLE constructive_compute_public.org_function_execution_logs
ADD COLUMN log_level text;
ALTER TABLE constructive_compute_public.org_function_execution_logs
ALTER COLUMN log_level SET NOT NULL;
ALTER TABLE constructive_compute_public.org_function_execution_logs
ALTER COLUMN log_level SET DEFAULT 'info';
COMMENT ON COLUMN constructive_compute_public.org_function_execution_logs.log_level IS 'Log severity: debug, info, warn, error';
ALTER TABLE constructive_compute_public.org_function_execution_logs
ADD CONSTRAINT org_function_execution_logs_log_level_chk
CHECK (log_level IN ('debug', 'info', 'warn', 'error'));
ALTER TABLE constructive_compute_public.org_function_execution_logs
ADD COLUMN message text;
ALTER TABLE constructive_compute_public.org_function_execution_logs
ALTER COLUMN message SET NOT NULL;
COMMENT ON COLUMN constructive_compute_public.org_function_execution_logs.message IS 'Log message text';
ALTER TABLE constructive_compute_public.org_function_execution_logs
ADD COLUMN metadata jsonb;
COMMENT ON COLUMN constructive_compute_public.org_function_execution_logs.metadata IS 'Structured context (labels, trace data, extra fields)';
ALTER TABLE constructive_compute_public.org_function_execution_logs
ADD COLUMN task_identifier text;
COMMENT ON COLUMN constructive_compute_public.org_function_execution_logs.task_identifier IS 'Function routing key (NULL for generic job logs)';
ALTER TABLE constructive_compute_public.org_function_execution_logs
ADD CONSTRAINT org_function_execution_logs_pkey PRIMARY KEY (created_at, id);
CREATE INDEX org_function_execution_logs_invocation_id_created_at_idx ON constructive_compute_public.org_function_execution_logs (invocation_id, created_at);
CREATE TABLE constructive_compute_public.org_function_invocations (
created_at timestamptz NOT NULL DEFAULT now()
) PARTITION BY RANGE (created_at);
ALTER TABLE constructive_compute_public.org_function_invocations
DISABLE ROW LEVEL SECURITY;
COMMENT ON TABLE constructive_compute_public.org_function_invocations IS 'Function invocation log — INSERT to call a function (business-layer, metered). Linked to definitions by task_identifier string.';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN actor_id uuid;
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.actor_id IS 'Who triggered the invocation (NULL for system/cron)';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN completed_at timestamptz;
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.completed_at IS 'When execution completed';
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.created_at IS 'Invocation creation timestamp (partition key)';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN duration_ms int;
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.duration_ms IS 'Wall-clock execution time in milliseconds';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN error text;
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.error IS 'Error message when status is failed';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN graph_execution_id uuid;
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.graph_execution_id IS 'Groups all node invocations from a single flow graph execution';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN id uuid;
ALTER TABLE constructive_compute_public.org_function_invocations
ALTER COLUMN id SET NOT NULL;
ALTER TABLE constructive_compute_public.org_function_invocations
ALTER COLUMN id SET DEFAULT uuidv7();
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.id IS 'Unique invocation identifier';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN job_id bigint;
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.job_id IS 'FK to app_jobs.jobs — the underlying transport';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN parent_invocation_id uuid;
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.parent_invocation_id IS 'Parent invocation when this is a child node of a flow graph execution';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN payload jsonb;
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.payload IS 'Function input payload';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN result jsonb;
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.result IS 'Function return value (success) or structured error (failure)';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN started_at timestamptz;
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.started_at IS 'When execution started';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN status text;
ALTER TABLE constructive_compute_public.org_function_invocations
ALTER COLUMN status SET NOT NULL;
ALTER TABLE constructive_compute_public.org_function_invocations
ALTER COLUMN status SET DEFAULT 'pending';
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.status IS 'Lifecycle: pending → running → completed/failed/cancelled';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD CONSTRAINT org_function_invocations_status_chk
CHECK (status IN ('pending', 'running', 'completed', 'failed', 'cancelled'));
ALTER TABLE constructive_compute_public.org_function_invocations
ADD COLUMN task_identifier text;
ALTER TABLE constructive_compute_public.org_function_invocations
ALTER COLUMN task_identifier SET NOT NULL;
COMMENT ON COLUMN constructive_compute_public.org_function_invocations.task_identifier IS 'Function routing slug (scope:name). Links to function_definitions.task_identifier by convention — no FK.';
ALTER TABLE constructive_compute_public.org_function_invocations
ADD CONSTRAINT org_function_invocations_pkey PRIMARY KEY (created_at, id);
CREATE INDEX org_function_invocations_actor_id_created_at_idx ON constructive_compute_public.org_function_invocations (actor_id, created_at);
CREATE INDEX org_function_invocations_graph_execution_id_created_at_idx ON constructive_compute_public.org_function_invocations (graph_execution_id, created_at);
CREATE INDEX org_function_invocations_task_identifier_created_at_idx ON constructive_compute_public.org_function_invocations (task_identifier, created_at);
CREATE TABLE constructive_compute_public.platform_function_definitions ();
ALTER TABLE constructive_compute_public.platform_function_definitions
DISABLE ROW LEVEL SECURITY;
COMMENT ON TABLE constructive_compute_public.platform_function_definitions IS 'Function definitions — registered cloud functions with routing, queue, and retry configuration';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN created_at timestamptz;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN created_at SET DEFAULT now();
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN description text;
COMMENT ON COLUMN constructive_compute_public.platform_function_definitions.description IS 'Human-readable description of what this function does';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN id uuid;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN id SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN id SET DEFAULT uuidv7();
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN is_built_in boolean;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN is_built_in SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN is_built_in SET DEFAULT false;
COMMENT ON COLUMN constructive_compute_public.platform_function_definitions.is_built_in IS 'Whether this function is a built-in platform function (synced from platform) vs user-created';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN is_invocable boolean;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN is_invocable SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN is_invocable SET DEFAULT false;
COMMENT ON COLUMN constructive_compute_public.platform_function_definitions.is_invocable IS 'Whether this function can be called via function_invocations (public API). Default false = internal-only via add_job()';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN max_attempts int;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN max_attempts SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN max_attempts SET DEFAULT 25;
COMMENT ON COLUMN constructive_compute_public.platform_function_definitions.max_attempts IS 'Maximum retry attempts for the underlying job';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN name text;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN name SET NOT NULL;
COMMENT ON COLUMN constructive_compute_public.platform_function_definitions.name IS 'Function name within scope (e.g. send_verification_link, process_file_embedding)';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN namespace_id uuid;
COMMENT ON COLUMN constructive_compute_public.platform_function_definitions.namespace_id IS 'Namespace this function belongs to (FK to namespaces table)';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN priority int;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN priority SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN priority SET DEFAULT 0;
COMMENT ON COLUMN constructive_compute_public.platform_function_definitions.priority IS 'Job priority (lower = higher priority)';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN queue_name text;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN queue_name SET NOT NULL;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN queue_name SET DEFAULT 'default';
COMMENT ON COLUMN constructive_compute_public.platform_function_definitions.queue_name IS 'Job queue name for serialization (e.g. email, ai, default)';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN scope text;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN scope SET NOT NULL;
COMMENT ON COLUMN constructive_compute_public.platform_function_definitions.scope IS 'Function grouping scope (e.g. email, embed, chunk, custom)';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN service_url text;
COMMENT ON COLUMN constructive_compute_public.platform_function_definitions.service_url IS 'Optional service URL override for function dispatch. NULL = use gateway convention (gatewayUrl/task_identifier). Set for customer-deployed functions or external endpoints.';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN task_identifier text;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN task_identifier SET NOT NULL;
COMMENT ON COLUMN constructive_compute_public.platform_function_definitions.task_identifier IS 'Computed routing slug: scope:name (used by Knative job worker for dispatch)';
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD COLUMN updated_at timestamptz;
ALTER TABLE constructive_compute_public.platform_function_definitions
ALTER COLUMN updated_at SET DEFAULT now();
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD CONSTRAINT platform_function_definitions_namespace_id_fkey
FOREIGN KEY(namespace_id)
REFERENCES constructive_infra_public.platform_namespaces (id)
ON DELETE SET NULL;
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD CONSTRAINT platform_function_definitions_pkey PRIMARY KEY (id);
ALTER TABLE constructive_compute_public.platform_function_definitions
ADD CONSTRAINT platform_function_definitions_scope_name_key
UNIQUE (scope, name);
CREATE INDEX platform_function_definitions_created_at_idx ON constructive_compute_public.platform_function_definitions (created_at);
CREATE INDEX platform_function_definitions_updated_at_idx ON constructive_compute_public.platform_function_definitions (updated_at);
CREATE FUNCTION constructive_compute_private.platform_complete_node(
IN execution_id uuid,
IN node_name text,
IN output_data jsonb
) RETURNS void AS $EOFCODE$
DECLARE
v_exec "constructive_compute_public".platform_function_graph_executions;
v_output_hash bytea;
v_obj_id uuid;
BEGIN
SELECT *
FROM "constructive_compute_public".platform_function_graph_executions
WHERE
id = platform_complete_node.execution_id INTO v_exec;
IF NOT (FOUND) THEN
RAISE EXCEPTION 'execution not found';
END IF;
IF v_exec.status != 'running' THEN
RAISE EXCEPTION 'execution is not running';
END IF;
v_output_hash := digest(platform_complete_node.output_data::text, 'sha256');
INSERT INTO "constructive_compute_public".platform_function_graph_execution_outputs (
database_id,
hash,
data
)
VALUES
(v_exec.database_id, v_output_hash, platform_complete_node.output_data)
ON CONFLICT (database_id, hash, created_at) DO NOTHING
RETURNING id INTO v_obj_id;
IF v_obj_id IS NULL THEN
SELECT id
FROM "constructive_compute_public".platform_function_graph_execution_outputs
WHERE
database_id = v_exec.database_id AND hash = v_output_hash INTO v_obj_id;
END IF;
UPDATE "constructive_compute_public".platform_function_graph_executions SET
node_outputs = node_outputs || jsonb_build_object(platform_complete_node.node_name, v_obj_id)
WHERE
id = platform_complete_node.execution_id;
UPDATE "constructive_compute_public".platform_function_graph_execution_node_states AS ns SET
status = 'completed', completed_at = now(), output_id = v_obj_id
WHERE
ns.execution_id = platform_complete_node.execution_id AND ns.node_name = platform_complete_node.node_name;
PERFORM "constructive_compute_private".platform_tick_execution(platform_complete_node.execution_id);
END;
$EOFCODE$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
CREATE FUNCTION constructive_compute_private.platform_copy_subtree(
IN source_scope_id uuid,
IN source_commit_id uuid,
IN source_path text[],
IN target_scope_id uuid,
IN target_root_hash uuid,
IN target_path text[]
) RETURNS uuid AS $EOFCODE$
DECLARE
v_source_tree_id uuid;
v_root_hash uuid;
v_row record;
v_rel_path text[];
v_new_path text[];
v_src_len int;
BEGIN
SELECT tree_id
FROM "constructive_platform_function_graph_public".platform_function_graph_commit
WHERE
id = platform_copy_subtree.source_commit_id AND database_id = platform_copy_subtree.source_scope_id INTO v_source_tree_id;
IF v_source_tree_id IS NULL THEN
RAISE EXCEPTION 'source commit not found';
END IF;
v_src_len := cardinality(platform_copy_subtree.source_path);
v_root_hash := platform_copy_subtree.target_root_hash;
FOR v_row IN SELECT
path,
data
FROM "constructive_platform_function_graph_public".get_all(platform_copy_subtree.source_scope_id, v_source_tree_id)
WHERE
(path)[1:v_src_len] = platform_copy_subtree.source_path AND cardinality(path) > v_src_len LOOP
v_rel_path := (v_row.path)[v_src_len + 1:];
v_new_path := platform_copy_subtree.target_path || v_rel_path;
v_root_hash := "constructive_platform_function_graph_public".insert_node_at_path(platform_copy_subtree.target_scope_id, v_root_hash, v_new_path, v_row.data, '{}'::uuid[], '{}'::text[]);
END LOOP;
RETURN v_root_hash;
END;
$EOFCODE$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
CREATE FUNCTION constructive_compute_private.platform_deserialize_graph(
IN database_id uuid,
IN name text,
IN snapshot jsonb
) RETURNS uuid AS $EOFCODE$
DECLARE
v_store_id uuid;
v_root_hash uuid;
v_graph_id uuid;
v_row record;
v_key text;
v_entry jsonb;
BEGIN
INSERT INTO "constructive_platform_function_graph_public".platform_function_graph_store (
database_id,
name
)
VALUES
(platform_deserialize_graph.database_id, platform_deserialize_graph.name)
RETURNING id INTO v_store_id;
PERFORM "constructive_platform_function_graph_public".init_empty_repo(platform_deserialize_graph.database_id, v_store_id);
FOR v_row IN SELECT *
FROM jsonb_each(platform_deserialize_graph.tree_data->'tree') LOOP
v_entry := v_row.value;
v_root_hash := "constructive_platform_function_graph_public".insert_node_at_path(platform_deserialize_graph.database_id, v_root_hash, (v_entry->'path')::text[], v_entry->'data', '{}'::uuid[], '{}'::text[]);
END LOOP;
INSERT INTO "constructive_compute_public".platform_function_graphs (
database_id,
store_id,
name,
description,
context
)
VALUES
(platform_deserialize_graph.database_id, v_store_id, platform_deserialize_graph.name, platform_deserialize_graph.tree_data->>'description', platform_deserialize_graph.tree_data->>'context')
RETURNING id INTO v_graph_id;
UPDATE "constructive_platform_function_graph_public".platform_function_graph_ref AS r SET
commit_id = (SELECT id
FROM "constructive_platform_function_graph_public".platform_function_graph_commit
WHERE
database_id = platform_deserialize_graph.database_id AND store_id = v_store_id
ORDER BY
created_at DESC
LIMIT
1)
WHERE
r.database_id = platform_deserialize_graph.database_id AND (r.store_id = v_store_id AND r.name = 'main');
RETURN v_graph_id;
END;
$EOFCODE$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
CREATE FUNCTION constructive_compute_private.platform_insert_subnet_nodes(
IN database_id uuid,
IN root_hash uuid,
IN base_path text[],
IN nodes_json jsonb,
IN edges_json jsonb DEFAULT NULL
) RETURNS uuid AS $EOFCODE$
DECLARE
v_node jsonb;
v_edge jsonb;
v_node_name text;
v_node_data jsonb;
v_edge_idx int := 0;
v_root uuid;
BEGIN
v_root := platform_insert_subnet_nodes.root_hash;
IF platform_insert_subnet_nodes.nodes_json IS NOT NULL THEN
FOR v_node IN SELECT *
FROM jsonb_array_elements(platform_insert_subnet_nodes.nodes_json) LOOP
v_node_name := v_node->>'name';
v_node_data := jsonb_build_object('type', v_node->>'type');
IF v_node ? 'meta' THEN
v_node_data := v_node_data || jsonb_build_object('meta', v_node->'meta');
END IF;
IF v_node ? 'props' THEN
v_node_data := v_node_data || jsonb_build_object('props', v_node->'props');
END IF;
v_root := "constructive_platform_function_graph_public".insert_node_at_path(platform_insert_subnet_nodes.database_id, v_root, platform_insert_subnet_nodes.base_path || ARRAY['nodes', v_node_name], v_node_data, '{}'::uuid[], '{}'::text[]);
IF v_node ? 'nodes' THEN
v_root := "constructive_compute_private".platform_insert_subnet_nodes(platform_insert_subnet_nodes.database_id, v_root, platform_insert_subnet_nodes.base_path || ARRAY['nodes', v_node_name], v_node->'nodes', v_node->'edges');
END IF;
END LOOP;
END IF;
IF platform_insert_subnet_nodes.edges_json IS NOT NULL THEN
FOR v_edge IN SELECT *
FROM jsonb_array_elements(platform_insert_subnet_nodes.edges_json) LOOP
v_root := "constructive_platform_function_graph_public".insert_node_at_path(platform_insert_subnet_nodes.database_id, v_root, platform_insert_subnet_nodes.base_path || ARRAY['edges', v_edge_idx::text], jsonb_build_object('src', v_edge->'src', 'dst', v_edge->'dst'), '{}'::uuid[], '{}'::text[]);
v_edge_idx := v_edge_idx + 1;
END LOOP;
END IF;
RETURN v_root;
END;
$EOFCODE$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
CREATE FUNCTION constructive_compute_private.platform_serialize_graph(
IN graph_id uuid
) RETURNS jsonb AS $EOFCODE$
DECLARE
v_graph "constructive_compute_public".platform_function_graphs;
v_tree_id uuid;
v_row record;
v_result jsonb;
v_nodes jsonb := '{}'::jsonb;
v_edges jsonb := '{}'::jsonb;
BEGIN
SELECT *
FROM "constructive_compute_public".platform_function_graphs
WHERE
id = platform_serialize_graph.graph_id INTO v_graph;
IF NOT (FOUND) THEN
RAISE EXCEPTION 'function_graph not found';
END IF;
SELECT c.tree_id
FROM "constructive_platform_function_graph_public".platform_function_graph_ref AS r INNER JOIN "constructive_platform_function_graph_public".platform_function_graph_commit AS c ON c.id = r.commit_id AND c.database_id = r.database_id
WHERE
(r.database_id = v_graph.database_id AND r.store_id = v_graph.store_id) AND r.name = 'main' INTO v_tree_id;
IF v_tree_id IS NULL THEN
RAISE EXCEPTION 'no tree found for graph';
END IF;
FOR v_row IN SELECT
path,
data
FROM "constructive_platform_function_graph_public".get_all(v_graph.database_id, v_tree_id) LOOP
v_nodes := v_nodes || jsonb_build_object(array_to_string(v_row.path, '/'), jsonb_build_object('path', v_row.path, 'data', v_row.data));
END LOOP;
v_result := jsonb_build_object('name', v_graph.name, 'context', v_graph.context, 'description', v_graph.description, 'tree', v_nodes);
RETURN v_result;
END;
$EOFCODE$ LANGUAGE plpgsql STABLE SECURITY DEFINER;
CREATE FUNCTION constructive_compute_private.platform_tick_execution(
IN execution_id uuid
) RETURNS int AS $EOFCODE$
DECLARE
v_exec "constructive_compute_public".platform_function_graph_executions;
v_graph "constructive_compute_public".platform_function_graphs;
v_tree_id uuid;
v_jobs_enqueued int := 0;
v_nodes jsonb := '[]'::jsonb;
v_edges jsonb := '[]'::jsonb;
v_node_map jsonb := '{}'::jsonb;
v_node jsonb;
v_node_name text;
v_node_type text;
v_i int;
v_is_ready boolean;
v_edge jsonb;
v_src_node text;
v_src_port text;
v_src_output jsonb;
v_src_obj_id text;
v_inputs jsonb;
v_output_data jsonb;
v_output_hash bytea;
v_obj_id uuid;
v_pending_jobs int;
v_def_data jsonb;
v_sub_graph_id uuid;
v_node_path text[];
BEGIN
SELECT *
FROM "constructive_compute_public".platform_function_graph_executions
WHERE
id = platform_tick_execution.execution_id INTO v_exec;
IF NOT (FOUND) THEN
RAISE EXCEPTION 'execution not found';
END IF;
IF v_exec.status != 'running' THEN
RETURN 0;
END IF;
IF v_exec.tick_count >= v_exec.max_ticks THEN
UPDATE "constructive_compute_public".platform_function_graph_executions SET
status = 'failed', completed_at = now(), error_code = 'TICK_LIMIT_EXCEEDED', error_message = ('execution exceeded ' || v_exec.max_ticks) || ' ticks'
WHERE
id = platform_tick_execution.execution_id;
RETURN 0;
END IF;
IF now() >= v_exec.timeout_at THEN
UPDATE "constructive_compute_public".platform_function_graph_executions SET
status = 'failed', completed_at = now(), error_code = 'EXECUTION_TIMEOUT', error_message = 'execution timed out'
WHERE
id = platform_tick_execution.execution_id;
RETURN 0;
END IF;
SELECT *
FROM "constructive_compute_public".platform_function_graphs
WHERE
id = v_exec.graph_id INTO v_graph;
SELECT c.tree_id
FROM "constructive_platform_function_graph_public".platform_function_graph_ref AS r INNER JOIN "constructive_platform_function_graph_public".platform_function_graph_commit AS c ON c.id = r.commit_id AND c.database_id = r.database_id
WHERE
(r.database_id = v_graph.database_id AND r.store_id = v_graph.store_id) AND r.name = 'main' INTO v_tree_id;
IF v_tree_id IS NULL THEN
RAISE EXCEPTION 'no tree found for graph';
END IF;
FOR v_node IN SELECT jsonb_build_object('name', (path)[5], 'type', data->>'type', 'props', data->'props', 'path', to_jsonb(path))
FROM "constructive_platform_function_graph_public".get_all(v_graph.database_id, v_tree_id)
WHERE
(cardinality(path) = 5 AND (path)[4] = 'nodes') AND ((path)[1] = v_graph.context AND ((path)[2] = 'graphs' AND (path)[3] = v_graph.name)) LOOP
v_nodes := v_nodes || jsonb_build_array(v_node);
v_node_map := v_node_map || jsonb_build_object(v_node->>'name', v_node);
END LOOP;
FOR v_node IN SELECT data
FROM "constructive_platform_function_graph_public".get_all(v_graph.database_id, v_tree_id)
WHERE
(cardinality(path) = 5 AND (path)[4] = 'edges') AND ((path)[1] = v_graph.context AND ((path)[2] = 'graphs' AND (path)[3] = v_graph.name))
ORDER BY
(path)[5]::integer LOOP
v_edges := v_edges || jsonb_build_array(v_node);
END LOOP;
FOR v_i IN 0..jsonb_array_length(v_nodes) - 1 LOOP
v_node := v_nodes->v_i;
v_node_name := v_node->>'name';
v_node_type := v_node->>'type';
IF v_node_type IN ( 'graphInput', 'graphProp' ) THEN
CONTINUE;
END IF;
IF v_exec.node_outputs ? v_node_name THEN
CONTINUE;
END IF;
v_is_ready := true;
v_inputs := '{}'::jsonb;
FOR v_edge IN SELECT value
FROM jsonb_array_elements(v_edges) AS value
WHERE
((value->'dst')->>'node') = v_node_name LOOP
v_src_node := (v_edge->'src')->>'node';
v_src_port := (v_edge->'src')->>'port';
IF NOT (v_exec.node_outputs ? v_src_node) THEN
v_is_ready := false;
EXIT;
END IF;
v_src_obj_id := v_exec.node_outputs->>v_src_node;
SELECT data
FROM "constructive_compute_public".platform_function_graph_execution_outputs
WHERE
id = v_src_obj_id::uuid INTO v_src_output;
IF v_src_output IS NULL THEN
v_is_ready := false;
EXIT;
END IF;
IF v_src_output ? v_src_port THEN
v_inputs := v_inputs || jsonb_build_object((v_edge->'dst')->>'port', v_src_output->v_src_port);
ELSIF v_src_output ? 'value' THEN
v_inputs := v_inputs || jsonb_build_object((v_edge->'dst')->>'port', v_src_output->'value');
ELSE
v_inputs := v_inputs || jsonb_build_object((v_edge->'dst')->>'port', v_src_output);
END IF;
END LOOP;
IF NOT (v_is_ready) THEN
CONTINUE;
END IF;
IF v_node_type = 'graphOutput' THEN
v_output_hash := digest(v_inputs::text, 'sha256');
INSERT INTO "constructive_compute_public".platform_function_graph_execution_outputs (
database_id,
hash,
data
)
VALUES
(v_exec.database_id, v_output_hash, v_inputs)
ON CONFLICT (database_id, hash, created_at) DO NOTHING
RETURNING id INTO v_obj_id;
IF v_obj_id IS NULL THEN
SELECT id
FROM "constructive_compute_public".platform_function_graph_execution_outputs
WHERE
database_id = v_exec.database_id AND hash = v_output_hash INTO v_obj_id;
END IF;
UPDATE "constructive_compute_public".platform_function_graph_executions SET
node_outputs = node_outputs || jsonb_build_object(v_node_name, v_obj_id)
WHERE
id = platform_tick_execution.execution_id
RETURNING * INTO v_exec;
CONTINUE;
END IF;
SELECT data
FROM "constructive_platform_function_graph_public".get_node_at_path(v_graph.database_id, v_tree_id, ARRAY[v_graph.context, 'definitions', v_node_type]) AS def INTO v_def_data;
IF v_def_data IS NULL THEN
SELECT data
FROM "constructive_platform_function_graph_public".get_node_at_path(v_graph.database_id, v_tree_id, ARRAY[v_graph.context, 'definitions', v_node_name]) AS def INTO v_def_data;
END IF;
IF v_def_data IS NOT NULL AND v_def_data ? 'graph' THEN
SELECT "constructive_compute_public".platform_import_graph_json(v_graph.database_id, ('def_' || platform_tick_execution.execution_id) || ('_' || v_node_name), v_def_data->'graph') INTO v_sub_graph_id;
PERFORM "constructive_compute_public".platform_start_execution(graph_id:=v_sub_graph_id, input_payload:=v_inputs, parent_execution_id:=platform_tick_execution.execution_id, parent_node_name:=v_node_name);
v_jobs_enqueued := v_jobs_enqueued + 1;
CONTINUE;
END IF;