Skip to content

Commit fbdf8be

Browse files
committed
fix(pgpm): stub procedure bodies + add revert scripts for node_states
Procedures (fail_node, complete_node, tick_execution) are now stubs — actual bodies are generated at provision time by graph_module AST builders. Added 36 revert scripts for all node_states table entries (table, columns, alterations, indexes, constraints) to fix pgpm deploy test.
1 parent 7fbfe40 commit fbdf8be

40 files changed

Lines changed: 171 additions & 535 deletions

File tree

pgpm/constructive-compute/deploy/schemas/constructive_compute_private/procedures/platform_complete_node/procedure.sql

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,8 @@ CREATE FUNCTION "constructive_compute_private".platform_complete_node(
99
IN node_name text,
1010
IN output_data jsonb
1111
) RETURNS void AS $_PGFN_$
12-
DECLARE
13-
v_exec "constructive_compute_private".platform_function_graph_executions;
14-
v_output_hash bytea;
15-
v_obj_id uuid;
1612
BEGIN
17-
SELECT *
18-
FROM "constructive_compute_private".platform_function_graph_executions
19-
WHERE
20-
id = platform_complete_node.execution_id INTO v_exec;
21-
IF NOT (FOUND) THEN
22-
RAISE EXCEPTION 'execution not found';
23-
END IF;
24-
IF v_exec.status != 'running' THEN
25-
RAISE EXCEPTION 'execution is not running';
26-
END IF;
27-
v_output_hash := digest(platform_complete_node.output_data::text, 'sha256');
28-
INSERT INTO "constructive_compute_private".platform_function_graph_execution_outputs (
29-
database_id,
30-
hash,
31-
data
32-
)
33-
VALUES
34-
(v_exec.database_id, v_output_hash, platform_complete_node.output_data)
35-
ON CONFLICT (database_id, hash, created_at) DO NOTHING
36-
RETURNING id INTO v_obj_id;
37-
IF v_obj_id IS NULL THEN
38-
SELECT id
39-
FROM "constructive_compute_private".platform_function_graph_execution_outputs
40-
WHERE
41-
database_id = v_exec.database_id AND hash = v_output_hash INTO v_obj_id;
42-
END IF;
43-
UPDATE "constructive_compute_private".platform_function_graph_executions SET
44-
node_outputs = node_outputs || jsonb_build_object(platform_complete_node.node_name, v_obj_id)
45-
WHERE
46-
id = platform_complete_node.execution_id;
47-
UPDATE "constructive_compute_private".platform_function_graph_execution_node_states AS ns SET
48-
status = 'completed', completed_at = now(), output_id = v_obj_id
49-
WHERE
50-
ns.execution_id = platform_complete_node.execution_id AND ns.node_name = platform_complete_node.node_name;
51-
PERFORM "constructive_compute_private".platform_tick_execution(platform_complete_node.execution_id);
13+
RAISE EXCEPTION 'stub: replaced at provision time by graph_module';
5214
END;
5315
$_PGFN_$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
5416

pgpm/constructive-compute/deploy/schemas/constructive_compute_private/procedures/platform_fail_node/procedure.sql

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,8 @@ CREATE FUNCTION "constructive_compute_private".platform_fail_node(
1010
IN error_code text,
1111
IN error_message text
1212
) RETURNS void AS $_PGFN_$
13-
DECLARE
14-
v_exec "constructive_compute_private".platform_function_graph_executions;
1513
BEGIN
16-
SELECT *
17-
FROM "constructive_compute_private".platform_function_graph_executions
18-
WHERE
19-
id = platform_fail_node.execution_id INTO v_exec;
20-
IF NOT (FOUND) THEN
21-
RAISE EXCEPTION 'execution not found';
22-
END IF;
23-
IF v_exec.status != 'running' THEN
24-
RAISE EXCEPTION 'execution is not running';
25-
END IF;
26-
UPDATE "constructive_compute_private".platform_function_graph_execution_node_states AS ns SET
27-
status = 'failed', completed_at = now(), error_code = platform_fail_node.error_code, error_message = platform_fail_node.error_message
28-
WHERE
29-
ns.execution_id = platform_fail_node.execution_id AND ns.node_name = platform_fail_node.node_name;
30-
UPDATE "constructive_compute_private".platform_function_graph_executions SET
31-
status = 'failed', completed_at = now(), error_code = platform_fail_node.error_code, error_message = (('[' || platform_fail_node.node_name) || '] ') || platform_fail_node.error_message
32-
WHERE
33-
id = platform_fail_node.execution_id;
14+
RAISE EXCEPTION 'stub: replaced at provision time by graph_module';
3415
END;
3516
$_PGFN_$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
3617

pgpm/constructive-compute/deploy/schemas/constructive_compute_private/procedures/platform_tick_execution/procedure.sql

Lines changed: 1 addition & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -7,215 +7,7 @@
77
CREATE FUNCTION "constructive_compute_private".platform_tick_execution(
88
IN execution_id uuid
99
) RETURNS integer AS $_PGFN_$
10-
DECLARE
11-
v_exec "constructive_compute_private".platform_function_graph_executions;
12-
v_graph "constructive_compute_public".platform_function_graphs;
13-
v_tree_id uuid;
14-
v_jobs_enqueued int := 0;
15-
v_nodes jsonb := '[]'::jsonb;
16-
v_edges jsonb := '[]'::jsonb;
17-
v_node_map jsonb := '{}'::jsonb;
18-
v_node jsonb;
19-
v_node_name text;
20-
v_node_type text;
21-
v_i int;
22-
v_is_ready boolean;
23-
v_edge jsonb;
24-
v_src_node text;
25-
v_src_port text;
26-
v_src_output jsonb;
27-
v_src_obj_id text;
28-
v_inputs jsonb;
29-
v_output_data jsonb;
30-
v_output_hash bytea;
31-
v_obj_id uuid;
32-
v_pending_jobs int;
33-
v_def_data jsonb;
34-
v_sub_graph_id uuid;
3510
BEGIN
36-
SELECT *
37-
FROM "constructive_compute_private".platform_function_graph_executions
38-
WHERE
39-
id = platform_tick_execution.execution_id INTO v_exec;
40-
IF NOT (FOUND) THEN
41-
RAISE EXCEPTION 'execution not found';
42-
END IF;
43-
IF v_exec.status != 'running' THEN
44-
RETURN 0;
45-
END IF;
46-
IF v_exec.tick_count >= v_exec.max_ticks THEN
47-
UPDATE "constructive_compute_private".platform_function_graph_executions SET
48-
status = 'failed', completed_at = now(), error_code = 'TICK_LIMIT_EXCEEDED', error_message = ('execution exceeded ' || v_exec.max_ticks) || ' ticks'
49-
WHERE
50-
id = platform_tick_execution.execution_id;
51-
RETURN 0;
52-
END IF;
53-
IF now() >= v_exec.timeout_at THEN
54-
UPDATE "constructive_compute_private".platform_function_graph_executions SET
55-
status = 'failed', completed_at = now(), error_code = 'EXECUTION_TIMEOUT', error_message = 'execution timed out'
56-
WHERE
57-
id = platform_tick_execution.execution_id;
58-
RETURN 0;
59-
END IF;
60-
SELECT *
61-
FROM "constructive_compute_public".platform_function_graphs
62-
WHERE
63-
id = v_exec.graph_id INTO v_graph;
64-
SELECT c.tree_id
65-
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
66-
WHERE
67-
(r.database_id = v_graph.database_id AND r.store_id = v_graph.store_id) AND r.name = 'main' INTO v_tree_id;
68-
IF v_tree_id IS NULL THEN
69-
RAISE EXCEPTION 'no tree found for graph';
70-
END IF;
71-
FOR v_node IN SELECT jsonb_build_object('name', (path)[5], 'type', data->>'type', 'props', data->'props')
72-
FROM "constructive_platform_function_graph_public".get_all(v_graph.database_id, v_tree_id)
73-
WHERE
74-
(cardinality(path) = 5 AND (path)[4] = 'nodes') AND ((path)[1] = v_graph.context AND ((path)[2] = 'graphs' AND (path)[3] = v_graph.name)) LOOP
75-
v_nodes := v_nodes || jsonb_build_array(v_node);
76-
v_node_map := v_node_map || jsonb_build_object(v_node->>'name', v_node);
77-
END LOOP;
78-
FOR v_node IN SELECT data
79-
FROM "constructive_platform_function_graph_public".get_all(v_graph.database_id, v_tree_id)
80-
WHERE
81-
(cardinality(path) = 5 AND (path)[4] = 'edges') AND ((path)[1] = v_graph.context AND ((path)[2] = 'graphs' AND (path)[3] = v_graph.name))
82-
ORDER BY
83-
(path)[5]::integer LOOP
84-
v_edges := v_edges || jsonb_build_array(v_node);
85-
END LOOP;
86-
FOR v_i IN 0..jsonb_array_length(v_nodes) - 1 LOOP
87-
v_node := v_nodes->v_i;
88-
v_node_name := v_node->>'name';
89-
v_node_type := v_node->>'type';
90-
IF v_node_type IN ( 'graphInput', 'graphProp' ) THEN
91-
CONTINUE;
92-
END IF;
93-
IF v_exec.node_outputs ? v_node_name THEN
94-
CONTINUE;
95-
END IF;
96-
v_is_ready := true;
97-
v_inputs := '{}'::jsonb;
98-
FOR v_edge IN SELECT value
99-
FROM jsonb_array_elements(v_edges) AS value
100-
WHERE
101-
((value->'dst')->>'node') = v_node_name LOOP
102-
v_src_node := (v_edge->'src')->>'node';
103-
v_src_port := (v_edge->'src')->>'port';
104-
IF NOT (v_exec.node_outputs ? v_src_node) THEN
105-
v_is_ready := false;
106-
EXIT;
107-
END IF;
108-
v_src_obj_id := v_exec.node_outputs->>v_src_node;
109-
SELECT data
110-
FROM "constructive_compute_private".platform_function_graph_execution_outputs
111-
WHERE
112-
id = v_src_obj_id::uuid INTO v_src_output;
113-
IF v_src_output IS NULL THEN
114-
v_is_ready := false;
115-
EXIT;
116-
END IF;
117-
IF v_src_output ? v_src_port THEN
118-
v_inputs := v_inputs || jsonb_build_object((v_edge->'dst')->>'port', v_src_output->v_src_port);
119-
ELSIF v_src_output ? 'value' THEN
120-
v_inputs := v_inputs || jsonb_build_object((v_edge->'dst')->>'port', v_src_output->'value');
121-
ELSE
122-
v_inputs := v_inputs || jsonb_build_object((v_edge->'dst')->>'port', v_src_output);
123-
END IF;
124-
END LOOP;
125-
IF NOT (v_is_ready) THEN
126-
CONTINUE;
127-
END IF;
128-
IF v_node_type = 'graphOutput' THEN
129-
v_output_hash := digest(v_inputs::text, 'sha256');
130-
INSERT INTO "constructive_compute_private".platform_function_graph_execution_outputs (
131-
database_id,
132-
hash,
133-
data
134-
)
135-
VALUES
136-
(v_exec.database_id, v_output_hash, v_inputs)
137-
ON CONFLICT (database_id, hash, created_at) DO NOTHING
138-
RETURNING id INTO v_obj_id;
139-
IF v_obj_id IS NULL THEN
140-
SELECT id
141-
FROM "constructive_compute_private".platform_function_graph_execution_outputs
142-
WHERE
143-
database_id = v_exec.database_id AND hash = v_output_hash INTO v_obj_id;
144-
END IF;
145-
UPDATE "constructive_compute_private".platform_function_graph_executions SET
146-
node_outputs = node_outputs || jsonb_build_object(v_node_name, v_obj_id)
147-
WHERE
148-
id = platform_tick_execution.execution_id
149-
RETURNING * INTO v_exec;
150-
CONTINUE;
151-
END IF;
152-
SELECT data
153-
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;
154-
IF v_def_data IS NULL THEN
155-
SELECT data
156-
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;
157-
END IF;
158-
IF v_def_data IS NOT NULL AND v_def_data ? 'graph' THEN
159-
SELECT "constructive_platform_function_graph_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;
160-
PERFORM "constructive_platform_function_graph_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);
161-
v_jobs_enqueued := v_jobs_enqueued + 1;
162-
CONTINUE;
163-
END IF;
164-
SELECT (count(*))::integer
165-
FROM app_jobs.jobs
166-
WHERE
167-
(payload::jsonb->>'execution_id')::uuid = platform_tick_execution.execution_id INTO v_pending_jobs;
168-
IF (v_pending_jobs + v_jobs_enqueued) >= v_exec.max_pending_jobs THEN
169-
UPDATE "constructive_compute_private".platform_function_graph_executions SET
170-
status = 'failed', completed_at = now(), error_code = 'JOB_LIMIT_EXCEEDED', error_message = ('execution exceeded ' || v_exec.max_pending_jobs) || ' pending jobs'
171-
WHERE
172-
id = platform_tick_execution.execution_id;
173-
RETURN v_jobs_enqueued;
174-
END IF;
175-
INSERT INTO app_jobs.jobs (
176-
database_id,
177-
task_identifier,
178-
payload
179-
)
180-
VALUES
181-
(v_exec.database_id, v_node_type, (json_build_object('execution_id', v_exec.id, 'node_name', v_node_name, 'node_type', v_node_type, 'inputs', v_inputs))::json);
182-
UPDATE "constructive_compute_private".platform_function_graph_executions SET
183-
node_outputs = node_outputs || jsonb_build_object(v_node_name, NULL)
184-
WHERE
185-
id = platform_tick_execution.execution_id
186-
RETURNING * INTO v_exec;
187-
INSERT INTO "constructive_compute_private".platform_function_graph_execution_node_states (
188-
execution_id,
189-
database_id,
190-
node_name,
191-
status,
192-
started_at
193-
)
194-
VALUES
195-
(v_exec.id, v_exec.database_id, v_node_name, 'queued', now());
196-
v_jobs_enqueued := v_jobs_enqueued + 1;
197-
END LOOP;
198-
UPDATE "constructive_compute_private".platform_function_graph_executions SET
199-
tick_count = tick_count + 1
200-
WHERE
201-
id = platform_tick_execution.execution_id;
202-
IF v_jobs_enqueued = 0 AND v_exec.node_outputs ? v_exec.output_node THEN
203-
v_src_obj_id := v_exec.node_outputs->>v_exec.output_node;
204-
SELECT data
205-
FROM "constructive_compute_private".platform_function_graph_execution_outputs
206-
WHERE
207-
id = v_src_obj_id::uuid INTO v_output_data;
208-
IF v_output_data IS NOT NULL THEN
209-
UPDATE "constructive_compute_private".platform_function_graph_executions SET
210-
status = 'completed', completed_at = now(), output_payload = v_output_data
211-
WHERE
212-
id = platform_tick_execution.execution_id;
213-
IF v_exec.parent_execution_id IS NOT NULL THEN
214-
PERFORM "constructive_compute_private".platform_complete_node(v_exec.parent_execution_id, v_exec.parent_node_name, v_output_data);
215-
END IF;
216-
END IF;
217-
END IF;
218-
RETURN v_jobs_enqueued;
11+
RAISE EXCEPTION 'stub: replaced at provision time by graph_module';
21912
END;
22013
$_PGFN_$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
221-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Revert: schemas/constructive_compute_private/procedures/platform_fail_node/procedure
2+
3+
4+
DROP FUNCTION "constructive_compute_private".platform_fail_node(uuid, text, text, text);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Revert: schemas/constructive_compute_private/tables/platform_function_graph_execution_node_states/alterations/alt0000002696
2+
3+
4+
ALTER TABLE "constructive_compute_private".platform_function_graph_execution_node_states
5+
ENABLE ROW LEVEL SECURITY;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Revert: schemas/constructive_compute_private/tables/platform_function_graph_execution_node_states/alterations/alt0000002697
2+
3+
4+
COMMENT ON TABLE "constructive_compute_private".platform_function_graph_execution_node_states IS NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Revert: schemas/constructive_compute_private/tables/platform_function_graph_execution_node_states/columns/completed_at/alterations/alt0000002711
2+
3+
4+
COMMENT ON COLUMN "constructive_compute_private".platform_function_graph_execution_node_states.completed_at IS NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Revert: schemas/constructive_compute_private/tables/platform_function_graph_execution_node_states/columns/completed_at/column
2+
3+
4+
ALTER TABLE "constructive_compute_private".platform_function_graph_execution_node_states
5+
DROP COLUMN completed_at RESTRICT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Revert: schemas/constructive_compute_private/tables/platform_function_graph_execution_node_states/columns/created_at/alterations/alt0000002715
2+
3+
4+
COMMENT ON COLUMN "constructive_compute_private".platform_function_graph_execution_node_states.created_at IS NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Revert: schemas/constructive_compute_private/tables/platform_function_graph_execution_node_states/columns/created_at/column
2+
3+
4+
ALTER TABLE "constructive_compute_private".platform_function_graph_execution_node_states
5+
DROP COLUMN created_at RESTRICT;

0 commit comments

Comments
 (0)